Skip to content

0.2.0. #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .github/cover.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## 0.2.0

**Breaking changes:**

* The editor displays variables with dollar prefix (`$`).
* The `choices` property is renamed to `models` in the `DynamicValueModelConfiguration` interface.

## 0.1.0

First release! 🚀
6 changes: 3 additions & 3 deletions demos/webpack-app/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
"sequential-workflow-model": "^0.1.3",
"sequential-workflow-designer": "^0.13.0",
"sequential-workflow-machine": "^0.2.0",
"sequential-workflow-editor-model": "^0.1.0",
"sequential-workflow-editor": "^0.1.0"
"sequential-workflow-editor-model": "^0.2.0",
"sequential-workflow-editor": "^0.2.0"
},
"devDependencies": {
"ts-loader": "^9.4.2",
Expand All @@ -33,4 +33,4 @@
"@typescript-eslint/parser": "^5.47.0",
"eslint": "^8.30.0"
}
}
}
12 changes: 6 additions & 6 deletions demos/webpack-app/src/playground/default-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const definition: MyDefinition = {
sequence: [
{
id: 'a282bc1908816678905a3c94049478aa',
name: 'index < loops',
name: '$index < $loops',
type: 'loop',
componentType: 'container',
properties: {
Expand All @@ -20,28 +20,28 @@ const definition: MyDefinition = {
to: { modelId: 'nullableVariable', value: { name: 'loops' } },
increment: { modelId: 'number', value: 1 },
indexVariable: { name: 'index', type: 'number' },
variables: { variables: [{ name: 'diff', type: 'number' }] }
variables: { variables: [{ name: 'remainder', type: 'number' }] }
},
sequence: [
{
id: '32529a3fbef39d5e480df8454164edae',
name: 'diff = index % 2',
name: '$remainder = $index % 2',
type: 'calculate',
componentType: 'task',
properties: {
a: { modelId: 'nullableVariable', value: { name: 'index' } },
operator: '%',
b: { modelId: 'number', value: 2 },
result: { name: 'diff' }
result: { name: 'remainder' }
}
},
{
id: 'f2f35f162f009e7683cf31c24a1e9589',
name: 'If diff == 0',
name: 'If $remainder == 0',
type: 'if',
componentType: 'switch',
properties: {
a: { modelId: 'nullableVariable', value: { name: 'diff' } },
a: { modelId: 'nullableVariable', value: { name: 'remainder' } },
operator: '=',
b: { modelId: 'number', value: 0 }
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { createAtomActivity } from 'sequential-workflow-machine';
import { GlobalState } from '../global-state';
import { LogStep } from '../../model/log-step-model';
import { formatVariableName } from 'sequential-workflow-editor';

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

$logger.log(message);
Expand Down
16 changes: 8 additions & 8 deletions demos/webpack-app/src/playground/model/calculate-step-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface CalculateStep extends Step {

export const calculateStepModel = createStepModel<CalculateStep>('calculate', 'task', step => {
const val = dynamicValueModel({
choices: [
models: [
numberValueModel({}),
nullableVariableValueModel({
isRequired: true,
Expand All @@ -32,6 +32,13 @@ export const calculateStepModel = createStepModel<CalculateStep>('calculate', 't
]
});

step.property('result').value(
nullableVariableValueModel({
variableType: ValueKnownType.number,
isRequired: true
})
);

step.property('a').value(val).label('A');

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

step.property('b').value(val).label('B');

step.property('result').value(
nullableVariableValueModel({
variableType: ValueKnownType.number,
isRequired: true
})
);
});
2 changes: 1 addition & 1 deletion demos/webpack-app/src/playground/model/if-step-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export interface IfStep extends BranchedStep {

export const ifStepModel = createBranchedStepModel<IfStep>('if', 'switch', step => {
const val = dynamicValueModel({
choices: [
models: [
numberValueModel({}),
nullableVariableValueModel({
isRequired: true,
Expand Down
2 changes: 1 addition & 1 deletion demos/webpack-app/src/playground/model/log-step-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const logStepModel = createStepModel<LogStep>('log', 'task', step => {
step.property('message')
.value(
dynamicValueModel({
choices: [
models: [
stringValueModel({
minLength: 1
}),
Expand Down
6 changes: 3 additions & 3 deletions demos/webpack-app/src/playground/model/loop-step-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
.label('From')
.value(
dynamicValueModel({
choices: [
models: [
numberValueModel({}),
nullableVariableValueModel({
isRequired: true,
Expand All @@ -54,7 +54,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
.label('To')
.value(
dynamicValueModel({
choices: [
models: [
numberValueModel({}),
nullableVariableValueModel({
isRequired: true,
Expand All @@ -68,7 +68,7 @@ export const loopStepModel = createSequentialStepModel('loop', 'container', step
.label('Increment')
.value(
dynamicValueModel({
choices: [
models: [
numberValueModel({
defaultValue: 1
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export const setStringValueModel = createStepModel<SetStringValueStep>('setStrin
step.property('value')
.value(
dynamicValueModel({
choices: [
models: [
stringValueModel({
minLength: 1
}),
Expand Down
8 changes: 4 additions & 4 deletions editor/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor",
"version": "0.1.0",
"version": "0.2.0",
"type": "module",
"main": "./lib/esm/index.js",
"types": "./lib/index.d.ts",
Expand Down Expand Up @@ -46,11 +46,11 @@
"prettier:fix": "prettier --write ./src ./css"
},
"dependencies": {
"sequential-workflow-editor-model": "^0.1.0",
"sequential-workflow-editor-model": "^0.2.0",
"sequential-workflow-model": "^0.1.3"
},
"peerDependencies": {
"sequential-workflow-editor-model": "^0.1.0",
"sequential-workflow-editor-model": "^0.2.0",
"sequential-workflow-model": "^0.1.3"
},
"devDependencies": {
Expand Down Expand Up @@ -79,4 +79,4 @@
"lowcode",
"flow"
]
}
}
2 changes: 2 additions & 0 deletions editor/src/core/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './html';
export * from './variable-name-formatter';
7 changes: 7 additions & 0 deletions editor/src/core/variable-name-formatter.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { formatVariableName } from './variable-name-formatter';

describe('formatVariableName', () => {
it('returns proper name', () => {
expect(formatVariableName('lastName')).toBe('$lastName');
});
});
3 changes: 3 additions & 0 deletions editor/src/core/variable-name-formatter.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export function formatVariableName(name: string): string {
return `$${name}`;
}
1 change: 1 addition & 0 deletions editor/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './core';
export * from './value-editors';
export * from './editor-provider';
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { validationErrorComponent } from '../../components/validation-error-comp
import { Component } from '../../components/component';
import { buttonComponent } from '../../components/button-component';
import { rowComponent } from '../../components/row-component';
import { formatVariableName } from '../../core/variable-name-formatter';

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

const name = Html.element('span');
name.innerText = `${variable.name} (${variable.type})`;
name.innerText = `${formatVariableName(variable.name)} (${variable.type})`;

const deleteButton = buttonComponent('Delete');
deleteButton.onClick.subscribe(() => onDeleteClicked.forward());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { selectComponent } from '../../components/select-component';
import { Component } from '../../components/component';
import { rowComponent } from '../../components/row-component';
import { buttonComponent } from '../../components/button-component';
import { formatVariableName } from '../../core/variable-name-formatter';

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

function reloadVariableSelector() {
variables = context.getVariables(getSelectedValueType());
const variableNames = variables.map(variable => variable.name);
const variableNames = variables.map(variable => formatVariableName(variable.name));
variableSelect.setValues(['-', ...variableNames]);
}

Expand Down
20 changes: 10 additions & 10 deletions editor/src/value-editors/dynamic/dynamic-value-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ export function dynamicValueEditor(
context: ValueModelContext<DynamicValueModel>,
services: EditorServices
): ValueEditor<DynamicValueModel> {
if (!context.model.childModels) {
throw new Error('childModels is required');
if (!context.model.subModels) {
throw new Error('subModels is required');
}
const childModels = context.model.childModels;
const subModels = context.model.subModels;

function validate() {
if (editor) {
Expand All @@ -27,7 +27,7 @@ export function dynamicValueEditor(
}

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

function onTypeChanged() {
const newModel = childModels[childModelSelect.getSelectedIndex()];
const newModel = subModels[subModelSelect.getSelectedIndex()];
const defaultValue = {
modelId: newModel.id,
value: newModel.getDefaultValue(services.activator)
Expand All @@ -50,12 +50,12 @@ export function dynamicValueEditor(
}

const startValue = context.getValue();
const childModelSelect = selectComponent({
const subModelSelect = selectComponent({
size: 'small'
});
childModelSelect.setValues(context.model.childModels.map(model => model.id));
childModelSelect.selectIndex(context.model.childModels.findIndex(model => model.id === startValue.modelId));
childModelSelect.onSelected.subscribe(onTypeChanged);
subModelSelect.setValues(context.model.subModels.map(model => model.label));
subModelSelect.selectIndex(context.model.subModels.findIndex(model => model.id === startValue.modelId));
subModelSelect.onSelected.subscribe(onTypeChanged);

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

return {
view: container.view,
controlView: childModelSelect.view,
controlView: subModelSelect.view,
validate
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { valueEditorContainerComponent } from '../../components/value-editor-con
import { validationErrorComponent } from '../../components/validation-error-component';
import { rowComponent } from '../../components/row-component';
import { selectComponent } from '../../components/select-component';
import { formatVariableName } from '../../core/variable-name-formatter';

export const nullableVariableValueEditorId = 'nullableVariable';

Expand Down Expand Up @@ -31,12 +32,7 @@ export function nullableVariableValueEditor(
const select = selectComponent({
stretched: true
});
select.setValues([
'- Select variable -',
...variables.map(variable => {
return variable.name;
})
]);
select.setValues(['- Select variable -', ...variables.map(variable => formatVariableName(variable.name))]);
if (startValue) {
select.selectIndex(variables.findIndex(variable => variable.name === startValue.name) + 1);
} else {
Expand Down
4 changes: 2 additions & 2 deletions model/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sequential-workflow-editor-model",
"version": "0.1.0",
"version": "0.2.0",
"homepage": "https://nocode-js.com/",
"author": {
"name": "NoCode JS",
Expand Down Expand Up @@ -70,4 +70,4 @@
"lowcode",
"flow"
]
}
}
3 changes: 2 additions & 1 deletion model/src/model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@ export type ValueModelFactoryOfValue<TValue extends PropertyValue = PropertyValu

export interface ValueModel<TValue extends PropertyValue = PropertyValue, TConfiguration extends object = object> {
id: ValueModelId;
label: string;
path: Path;
configuration: TConfiguration;
childModels?: ValueModel[];
subModels?: ValueModel[];
getDefaultValue(activator: ModelActivator): TValue;
getVariableDefinitions(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): VariableDefinition[] | null;
validate(context: ValueModelContext<ValueModel<TValue, TConfiguration>>): ValidationResult;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export const anyVariablesValueModelId = 'anyVariables';
export function anyVariablesValueModel(configuration: AnyVariablesValueModelConfiguration): ValueModelFactory<AnyVariablesValueModel> {
return (path: Path) => ({
id: anyVariablesValueModelId,
label: 'Variables',
path,
configuration,
getDefaultValue() {
Expand Down
1 change: 1 addition & 0 deletions model/src/value-models/branches/branches-value-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export function branchesValueModel<TConfiguration extends BranchesValueModelConf
): ValueModelFactory<BranchesValueModel<BranchesOf<TConfiguration>>> {
return (path: Path) => ({
id: branchesValueModelId,
label: 'Branches',
path,
configuration,
getDefaultValue(activator: ModelActivator): BranchesOf<TConfiguration> {
Expand Down
1 change: 1 addition & 0 deletions model/src/value-models/choice/choice-value-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export function choiceValueModel(configuration: ChoiceValueModelConfiguration):

return (path: Path) => ({
id: choiceValueModelId,
label: 'Choice',
path,
configuration,
getDefaultValue() {
Expand Down
Loading