Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const sketch = function (rawSpec) {
const navigateEvent = 'navigateEvent';
const wrapperAdhocEvents = 'serializer-wrapper-events';
const formAdhocEvents = 'form-events';
const schema = ValueSchema.objOf([
FieldSchema.strict('fields'),
// Used for when datafields are present.
FieldSchema.defaulted('maxFieldIndex', rawSpec.fields.length - 1),
FieldSchema.strict('onExecute'),
FieldSchema.strict('getInitialValue'),
FieldSchema.state('state', function () {
return {
dialogSwipeState: Singleton.value(),
currentScreen: Cell(0)
};
})
]);
const spec = ValueSchema.asRawOrDie('SerialisedDialog', schema, rawSpec);
const navigationButton = function (direction, directionName, enabled) {
return Button.sketch({
dom: UiDomFactory.dom('<span class="${prefix}-icon-' + directionName + ' ${prefix}-icon"></span>'),
action (button) {
}
export interface BaseDialogMenuButtonInstanceApi {
isDisabled: () => boolean;
setDisabled: (state: boolean) => void;
isActive: () => boolean;
setActive: (state: boolean) => void;
}
export const baseDialogMenuButtonFields = [
FieldSchema.optionString('text'),
FieldSchema.optionString('tooltip'),
FieldSchema.optionString('icon'),
FieldSchema.strictArrayOf('items', dialogToggleMenuItemSchema),
FieldSchema.defaultedFunction('onSetup', () => Fun.noop),
FieldSchema.defaulted('storage', Cell(false))
];
FieldSchema.state('original', Fun.identity)
]));
const contextToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton'),
FieldSchema.defaulted('primary', false),
FieldSchema.strictFunction('onAction'),
FieldSchema.state('original', Fun.identity)
]));
const launchButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton')
]));
const launchToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformtogglebutton')
]));
const toggleOrNormal = ValueSchema.choose('type', {
contextformbutton: contextButtonSchema,
contextformtogglebutton: contextToggleButtonSchema
});
const contextFormSchema = ValueSchema.objOf([
FieldSchema.defaulted('type', 'contextform'),
FieldSchema.defaultedFunction('initValue', () => ''),
FieldSchema.optionString('label'),
FieldSchema.strictArrayOf('commands', toggleOrNormal),
FieldSchema.optionOf('launch', ValueSchema.choose('type', {
contextformbutton: launchButtonSchema,
contextformtogglebutton: launchToggleButtonSchema
}))
const launchButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton')
]));
const launchToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformtogglebutton')
]));
const toggleOrNormal = ValueSchema.choose('type', {
contextformbutton: contextButtonSchema,
contextformtogglebutton: contextToggleButtonSchema
});
const contextFormSchema = ValueSchema.objOf([
FieldSchema.defaulted('type', 'contextform'),
FieldSchema.defaultedFunction('initValue', () => ''),
FieldSchema.optionString('label'),
FieldSchema.strictArrayOf('commands', toggleOrNormal),
FieldSchema.optionOf('launch', ValueSchema.choose('type', {
contextformbutton: launchButtonSchema,
contextformtogglebutton: launchToggleButtonSchema
}))
].concat(contextBarFields));
const contextToolbarSchema = ValueSchema.objOf([
FieldSchema.defaulted('type', 'contexttoolbar'),
FieldSchema.strictString('items')
].concat(contextBarFields));
export const createContextToolbar = (spec: ContextToolbarApi): Result> => {
return ValueSchema.asRaw('ContextToolbar', contextToolbarSchema, spec);
branches: Record;
name: string;
active?: any;
apis?: { };
extra?: { };
state?: { };
}
const modeSchema: Processor = ValueSchema.objOfOnly([
FieldSchema.strict('branchKey'),
FieldSchema.strict('branches'),
FieldSchema.strict('name'),
FieldSchema.defaulted('active', { }),
FieldSchema.defaulted('apis', { }),
FieldSchema.defaulted('state', NoState),
FieldSchema.defaulted('extra', { })
]);
const createModes = (data: BehaviourModeSpec): AlloyBehaviour => {
const value: BehaviourModeSpec = ValueSchema.asRawOrDie('Creating behaviour: ' + data.name, modeSchema, data);
return CommonBehaviour.createModes(
ValueSchema.choose(value.branchKey, value.branches),
value.name, value.active, value.apis, value.extra, value.state
);
};
const revoke = Fun.constant(undefined);
const noActive = Fun.constant({ });
const noApis = Fun.constant({ });
const noExtra = Fun.constant({ });
export {
apis?: {};
extra?: {};
state?: {};
}
const derive = (
capabilities: Array>
): AlloyBehaviourRecord => {
return Objects.wrapAll(capabilities);
};
const simpleSchema: Processor = ValueSchema.objOfOnly([
FieldSchema.strict('fields'),
FieldSchema.strict('name'),
FieldSchema.defaulted('active', { }),
FieldSchema.defaulted('apis', { }),
FieldSchema.defaulted('state', NoState),
FieldSchema.defaulted('extra', { })
]);
const create = (data: AlloyBehaviourConfig): AlloyBehaviour => {
const value = ValueSchema.asRawOrDie('Creating behaviour: ' + data.name, simpleSchema, data);
return CommonBehaviour.create(value.fields, value.name, value.active, value.apis, value.extra, value.state);
};
export interface BehaviourModeSpec {
branchKey: string;
branches: Record;
name: string;
active?: any;
apis?: { };
extra?: { };
active?: {};
apis?: {};
extra?: {};
state?: {};
}
const derive = (
capabilities: Array>
): AlloyBehaviourRecord => {
return Objects.wrapAll(capabilities);
};
const simpleSchema: Processor = ValueSchema.objOfOnly([
FieldSchema.strict('fields'),
FieldSchema.strict('name'),
FieldSchema.defaulted('active', { }),
FieldSchema.defaulted('apis', { }),
FieldSchema.defaulted('state', NoState),
FieldSchema.defaulted('extra', { })
]);
const create = (data: AlloyBehaviourConfig): AlloyBehaviour => {
const value = ValueSchema.asRawOrDie('Creating behaviour: ' + data.name, simpleSchema, data);
return CommonBehaviour.create(value.fields, value.name, value.active, value.apis, value.extra, value.state);
};
export interface BehaviourModeSpec {
branchKey: string;
branches: Record;
name: string;
active?: any;
apis?: { };
branchKey: string;
branches: Record;
name: string;
active?: any;
apis?: { };
extra?: { };
state?: { };
}
const modeSchema: Processor = ValueSchema.objOfOnly([
FieldSchema.strict('branchKey'),
FieldSchema.strict('branches'),
FieldSchema.strict('name'),
FieldSchema.defaulted('active', { }),
FieldSchema.defaulted('apis', { }),
FieldSchema.defaulted('state', NoState),
FieldSchema.defaulted('extra', { })
]);
const createModes = (data: BehaviourModeSpec): AlloyBehaviour => {
const value: BehaviourModeSpec = ValueSchema.asRawOrDie('Creating behaviour: ' + data.name, modeSchema, data);
return CommonBehaviour.createModes(
ValueSchema.choose(value.branchKey, value.branches),
value.name, value.active, value.apis, value.extra, value.state
);
};
const revoke = Fun.constant(undefined);
const noActive = Fun.constant({ });
const noApis = Fun.constant({ });
const noExtra = Fun.constant({ });
const contextBarFields = [
FieldSchema.defaultedFunction('predicate', () => false),
FieldSchema.defaultedStringEnum('scope', 'node', ['node', 'editor']),
FieldSchema.defaultedStringEnum('position', 'selection', ['node', 'selection', 'line']),
];
const contextButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton'),
FieldSchema.defaulted('primary', false),
FieldSchema.strictFunction('onAction'),
FieldSchema.state('original', Fun.identity)
]));
const contextToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton'),
FieldSchema.defaulted('primary', false),
FieldSchema.strictFunction('onAction'),
FieldSchema.state('original', Fun.identity)
]));
const launchButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton')
]));
const launchToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformtogglebutton')
]));
const toggleOrNormal = ValueSchema.choose('type', {
contextformbutton: contextButtonSchema,
contextformtogglebutton: contextToggleButtonSchema
});
const contextButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton'),
FieldSchema.defaulted('primary', false),
FieldSchema.strictFunction('onAction'),
FieldSchema.state('original', Fun.identity)
]));
const contextToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton'),
FieldSchema.defaulted('primary', false),
FieldSchema.strictFunction('onAction'),
FieldSchema.state('original', Fun.identity)
]));
const launchButtonSchema = ValueSchema.objOf(baseToolbarButtonFields.concat([
FieldSchema.defaulted('type', 'contextformbutton')
]));
const launchToggleButtonSchema = ValueSchema.objOf(baseToolbarToggleButtonFields.concat([
FieldSchema.defaulted('type', 'contextformtogglebutton')
]));
const toggleOrNormal = ValueSchema.choose('type', {
contextformbutton: contextButtonSchema,
contextformtogglebutton: contextToggleButtonSchema
});
const contextFormSchema = ValueSchema.objOf([
FieldSchema.defaulted('type', 'contextform'),
FieldSchema.defaultedFunction('initValue', () => ''),
FieldSchema.optionString('label'),
FieldSchema.strictArrayOf('commands', toggleOrNormal),