Skip to content

Commit 91e6608

Browse files
authored
0.2.0. (#4)
1 parent 6ec029c commit 91e6608

32 files changed

+134
-58
lines changed

.github/cover.png

976 Bytes
Loading

CHANGELOG.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
## 0.2.0
2+
3+
**Breaking changes:**
4+
5+
* The editor displays variables with dollar prefix (`$`).
6+
* The `choices` property is renamed to `models` in the `DynamicValueModelConfiguration` interface.
7+
8+
## 0.1.0
9+
10+
First release! 🚀

demos/webpack-app/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
"sequential-workflow-model": "^0.1.3",
1919
"sequential-workflow-designer": "^0.13.0",
2020
"sequential-workflow-machine": "^0.2.0",
21-
"sequential-workflow-editor-model": "^0.1.0",
22-
"sequential-workflow-editor": "^0.1.0"
21+
"sequential-workflow-editor-model": "^0.2.0",
22+
"sequential-workflow-editor": "^0.2.0"
2323
},
2424
"devDependencies": {
2525
"ts-loader": "^9.4.2",
@@ -33,4 +33,4 @@
3333
"@typescript-eslint/parser": "^5.47.0",
3434
"eslint": "^8.30.0"
3535
}
36-
}
36+
}

demos/webpack-app/src/playground/default-state.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const definition: MyDefinition = {
1111
sequence: [
1212
{
1313
id: 'a282bc1908816678905a3c94049478aa',
14-
name: 'index < loops',
14+
name: '$index < $loops',
1515
type: 'loop',
1616
componentType: 'container',
1717
properties: {
@@ -20,28 +20,28 @@ const definition: MyDefinition = {
2020
to: { modelId: 'nullableVariable', value: { name: 'loops' } },
2121
increment: { modelId: 'number', value: 1 },
2222
indexVariable: { name: 'index', type: 'number' },
23-
variables: { variables: [{ name: 'diff', type: 'number' }] }
23+
variables: { variables: [{ name: 'remainder', type: 'number' }] }
2424
},
2525
sequence: [
2626
{
2727
id: '32529a3fbef39d5e480df8454164edae',
28-
name: 'diff = index % 2',
28+
name: '$remainder = $index % 2',
2929
type: 'calculate',
3030
componentType: 'task',
3131
properties: {
3232
a: { modelId: 'nullableVariable', value: { name: 'index' } },
3333
operator: '%',
3434
b: { modelId: 'number', value: 2 },
35-
result: { name: 'diff' }
35+
result: { name: 'remainder' }
3636
}
3737
},
3838
{
3939
id: 'f2f35f162f009e7683cf31c24a1e9589',
40-
name: 'If diff == 0',
40+
name: 'If $remainder == 0',
4141
type: 'if',
4242
componentType: 'switch',
4343
properties: {
44-
a: { modelId: 'nullableVariable', value: { name: 'diff' } },
44+
a: { modelId: 'nullableVariable', value: { name: 'remainder' } },
4545
operator: '=',
4646
b: { modelId: 'number', value: 0 }
4747
},

demos/webpack-app/src/playground/machine/activities/log-activity.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { createAtomActivity } from 'sequential-workflow-machine';
22
import { GlobalState } from '../global-state';
33
import { LogStep } from '../../model/log-step-model';
4+
import { formatVariableName } from 'sequential-workflow-editor';
45

56
export const logActivity = createAtomActivity<LogStep, GlobalState>({
67
init: () => ({}),
@@ -11,7 +12,8 @@ export const logActivity = createAtomActivity<LogStep, GlobalState>({
1112
for (const variable of step.properties.variables.variables) {
1213
const value = $variables.isSet(variable.name) ? $variables.read(variable.name) || '<empty>' : '<not set>';
1314
const type = typeof value;
14-
message += `\n${variable.name}=${value} (${type})`;
15+
const name = formatVariableName(variable.name);
16+
message += `\n${name}=${value} (${type})`;
1517
}
1618

1719
$logger.log(message);

demos/webpack-app/src/playground/model/calculate-step-model.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface CalculateStep extends Step {
2323

2424
export const calculateStepModel = createStepModel<CalculateStep>('calculate', 'task', step => {
2525
const val = dynamicValueModel({
26-
choices: [
26+
models: [
2727
numberValueModel({}),
2828
nullableVariableValueModel({
2929
isRequired: true,
@@ -32,6 +32,13 @@ export const calculateStepModel = createStepModel<CalculateStep>('calculate', 't
3232
]
3333
});
3434

35+
step.property('result').value(
36+
nullableVariableValueModel({
37+
variableType: ValueKnownType.number,
38+
isRequired: true
39+
})
40+
);
41+
3542
step.property('a').value(val).label('A');
3643

3744
step.property('operator').value(
@@ -41,11 +48,4 @@ export const calculateStepModel = createStepModel<CalculateStep>('calculate', 't
4148
);
4249

4350
step.property('b').value(val).label('B');
44-
45-
step.property('result').value(
46-
nullableVariableValueModel({
47-
variableType: ValueKnownType.number,
48-
isRequired: true
49-
})
50-
);
5151
});

demos/webpack-app/src/playground/model/if-step-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ export interface IfStep extends BranchedStep {
2323

2424
export const ifStepModel = createBranchedStepModel<IfStep>('if', 'switch', step => {
2525
const val = dynamicValueModel({
26-
choices: [
26+
models: [
2727
numberValueModel({}),
2828
nullableVariableValueModel({
2929
isRequired: true,

demos/webpack-app/src/playground/model/log-step-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ export const logStepModel = createStepModel<LogStep>('log', 'task', step => {
2424
step.property('message')
2525
.value(
2626
dynamicValueModel({
27-
choices: [
27+
models: [
2828
stringValueModel({
2929
minLength: 1
3030
}),

demos/webpack-app/src/playground/model/loop-step-model.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
3232
.label('From')
3333
.value(
3434
dynamicValueModel({
35-
choices: [
35+
models: [
3636
numberValueModel({}),
3737
nullableVariableValueModel({
3838
isRequired: true,
@@ -54,7 +54,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
5454
.label('To')
5555
.value(
5656
dynamicValueModel({
57-
choices: [
57+
models: [
5858
numberValueModel({}),
5959
nullableVariableValueModel({
6060
isRequired: true,
@@ -68,7 +68,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
6868
.label('Increment')
6969
.value(
7070
dynamicValueModel({
71-
choices: [
71+
models: [
7272
numberValueModel({
7373
defaultValue: 1
7474
}),

demos/webpack-app/src/playground/model/set-string-value-model.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export const setStringValueModel = createStepModel<SetStringValueStep>('setStrin
3030
step.property('value')
3131
.value(
3232
dynamicValueModel({
33-
choices: [
33+
models: [
3434
stringValueModel({
3535
minLength: 1
3636
}),

editor/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"type": "module",
55
"main": "./lib/esm/index.js",
66
"types": "./lib/index.d.ts",
@@ -46,11 +46,11 @@
4646
"prettier:fix": "prettier --write ./src ./css"
4747
},
4848
"dependencies": {
49-
"sequential-workflow-editor-model": "^0.1.0",
49+
"sequential-workflow-editor-model": "^0.2.0",
5050
"sequential-workflow-model": "^0.1.3"
5151
},
5252
"peerDependencies": {
53-
"sequential-workflow-editor-model": "^0.1.0",
53+
"sequential-workflow-editor-model": "^0.2.0",
5454
"sequential-workflow-model": "^0.1.3"
5555
},
5656
"devDependencies": {
@@ -79,4 +79,4 @@
7979
"lowcode",
8080
"flow"
8181
]
82-
}
82+
}

editor/src/core/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export * from './html';
2+
export * from './variable-name-formatter';
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { formatVariableName } from './variable-name-formatter';
2+
3+
describe('formatVariableName', () => {
4+
it('returns proper name', () => {
5+
expect(formatVariableName('lastName')).toBe('$lastName');
6+
});
7+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export function formatVariableName(name: string): string {
2+
return `$${name}`;
3+
}

editor/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1+
export * from './core';
12
export * from './value-editors';
23
export * from './editor-provider';

editor/src/value-editors/any-variables/any-variable-item-component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { validationErrorComponent } from '../../components/validation-error-comp
44
import { Component } from '../../components/component';
55
import { buttonComponent } from '../../components/button-component';
66
import { rowComponent } from '../../components/row-component';
7+
import { formatVariableName } from '../../core/variable-name-formatter';
78

89
export interface AnyVariableItemComponent extends Component {
910
onDeleteClicked: SimpleEvent<void>;
@@ -20,7 +21,7 @@ export function anyVariableItemComponent(variable: AnyVariable): AnyVariableItem
2021
const view = Html.element('div');
2122

2223
const name = Html.element('span');
23-
name.innerText = `${variable.name} (${variable.type})`;
24+
name.innerText = `${formatVariableName(variable.name)} (${variable.type})`;
2425

2526
const deleteButton = buttonComponent('Delete');
2627
deleteButton.onClick.subscribe(() => onDeleteClicked.forward());

editor/src/value-editors/any-variables/any-variable-selector-component.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { selectComponent } from '../../components/select-component';
1010
import { Component } from '../../components/component';
1111
import { rowComponent } from '../../components/row-component';
1212
import { buttonComponent } from '../../components/button-component';
13+
import { formatVariableName } from '../../core/variable-name-formatter';
1314

1415
export interface AnyVariableSelectorComponent extends Component {
1516
onAdded: SimpleEvent<AnyVariable>;
@@ -27,7 +28,7 @@ export function anyVariableSelectorComponent(context: ValueModelContext<AnyVaria
2728

2829
function reloadVariableSelector() {
2930
variables = context.getVariables(getSelectedValueType());
30-
const variableNames = variables.map(variable => variable.name);
31+
const variableNames = variables.map(variable => formatVariableName(variable.name));
3132
variableSelect.setValues(['-', ...variableNames]);
3233
}
3334

editor/src/value-editors/dynamic/dynamic-value-editor.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ export function dynamicValueEditor(
1010
context: ValueModelContext<DynamicValueModel>,
1111
services: EditorServices
1212
): ValueEditor<DynamicValueModel> {
13-
if (!context.model.childModels) {
14-
throw new Error('childModels is required');
13+
if (!context.model.subModels) {
14+
throw new Error('subModels is required');
1515
}
16-
const childModels = context.model.childModels;
16+
const subModels = context.model.subModels;
1717

1818
function validate() {
1919
if (editor) {
@@ -27,7 +27,7 @@ export function dynamicValueEditor(
2727
}
2828

2929
const value = context.getValue();
30-
const model = childModels.find(model => model.id === value.modelId);
30+
const model = subModels.find(model => model.id === value.modelId);
3131
if (!model || !model.id) {
3232
throw new Error(`Model not found: ${value.modelId}`);
3333
}
@@ -40,7 +40,7 @@ export function dynamicValueEditor(
4040
}
4141

4242
function onTypeChanged() {
43-
const newModel = childModels[childModelSelect.getSelectedIndex()];
43+
const newModel = subModels[subModelSelect.getSelectedIndex()];
4444
const defaultValue = {
4545
modelId: newModel.id,
4646
value: newModel.getDefaultValue(services.activator)
@@ -50,12 +50,12 @@ export function dynamicValueEditor(
5050
}
5151

5252
const startValue = context.getValue();
53-
const childModelSelect = selectComponent({
53+
const subModelSelect = selectComponent({
5454
size: 'small'
5555
});
56-
childModelSelect.setValues(context.model.childModels.map(model => model.id));
57-
childModelSelect.selectIndex(context.model.childModels.findIndex(model => model.id === startValue.modelId));
58-
childModelSelect.onSelected.subscribe(onTypeChanged);
56+
subModelSelect.setValues(context.model.subModels.map(model => model.label));
57+
subModelSelect.selectIndex(context.model.subModels.findIndex(model => model.id === startValue.modelId));
58+
subModelSelect.onSelected.subscribe(onTypeChanged);
5959

6060
const placeholder = Html.element('div', {
6161
class: 'swe-dynamic-placeholder'
@@ -67,7 +67,7 @@ export function dynamicValueEditor(
6767

6868
return {
6969
view: container.view,
70-
controlView: childModelSelect.view,
70+
controlView: subModelSelect.view,
7171
validate
7272
};
7373
}

editor/src/value-editors/nullable-variable/nullable-variable-value-editor.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { valueEditorContainerComponent } from '../../components/value-editor-con
44
import { validationErrorComponent } from '../../components/validation-error-component';
55
import { rowComponent } from '../../components/row-component';
66
import { selectComponent } from '../../components/select-component';
7+
import { formatVariableName } from '../../core/variable-name-formatter';
78

89
export const nullableVariableValueEditorId = 'nullableVariable';
910

@@ -31,12 +32,7 @@ export function nullableVariableValueEditor(
3132
const select = selectComponent({
3233
stretched: true
3334
});
34-
select.setValues([
35-
'- Select variable -',
36-
...variables.map(variable => {
37-
return variable.name;
38-
})
39-
]);
35+
select.setValues(['- Select variable -', ...variables.map(variable => formatVariableName(variable.name))]);
4036
if (startValue) {
4137
select.selectIndex(variables.findIndex(variable => variable.name === startValue.name) + 1);
4238
} else {

model/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sequential-workflow-editor-model",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"homepage": "https://nocode-js.com/",
55
"author": {
66
"name": "NoCode JS",
@@ -70,4 +70,4 @@
7070
"lowcode",
7171
"flow"
7272
]
73-
}
73+
}

model/src/model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ export type ValueModelFactoryOfValue<TValue extends PropertyValue = PropertyValu
4242

4343
export interface ValueModel<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object> {
4444
id: ValueModelId;
45+
label: string;
4546
path: Path;
4647
configuration: TConfiguration;
47-
childModels?: ValueModel[];
48+
subModels?: ValueModel[];
4849
getDefaultValue(activator: ModelActivator): TValue;
4950
getVariableDefinitions(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): VariableDefinition[] | null;
5051
validate(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): ValidationResult;

model/src/value-models/any-variable/any-variables-value-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export const anyVariablesValueModelId = 'anyVariables';
1414
export function anyVariablesValueModel(configuration: AnyVariablesValueModelConfiguration): ValueModelFactory<AnyVariablesValueModel> {
1515
return (path: Path) => ({
1616
id: anyVariablesValueModelId,
17+
label: 'Variables',
1718
path,
1819
configuration,
1920
getDefaultValue() {

model/src/value-models/branches/branches-value-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function branchesValueModel<TConfiguration extends BranchesValueModelConf
2121
): ValueModelFactory<BranchesValueModel<BranchesOf<TConfiguration>>> {
2222
return (path: Path) => ({
2323
id: branchesValueModelId,
24+
label: 'Branches',
2425
path,
2526
configuration,
2627
getDefaultValue(activator: ModelActivator): BranchesOf<TConfiguration> {

model/src/value-models/choice/choice-value-model.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export function choiceValueModel(configuration: ChoiceValueModelConfiguration):
1818

1919
return (path: Path) => ({
2020
id: choiceValueModelId,
21+
label: 'Choice',
2122
path,
2223
configuration,
2324
getDefaultValue() {

0 commit comments

Comments
 (0)