How to use the @ephox/boulder.FieldSchema.defaulted function in @ephox/boulder

To help you get started, we’ve selected a few @ephox/boulder examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github tinymce / tinymce / modules / tinymce / src / themes / mobile / main / ts / ui / SerialisedDialog.ts View on Github external
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) {
github tinymce / tinymce / modules / bridge / src / main / ts / ephox / bridge / components / dialog / MenuButton.ts View on Github external
}

export interface BaseDialogMenuButtonInstanceApi {
  isDisabled: () =&gt; boolean;
  setDisabled: (state: boolean) =&gt; void;
  isActive: () =&gt; boolean;
  setActive: (state: boolean) =&gt; void;
}

export const baseDialogMenuButtonFields = [
  FieldSchema.optionString('text'),
  FieldSchema.optionString('tooltip'),
  FieldSchema.optionString('icon'),
  FieldSchema.strictArrayOf('items', dialogToggleMenuItemSchema),
  FieldSchema.defaultedFunction('onSetup', () =&gt; Fun.noop),
  FieldSchema.defaulted('storage', Cell(false))
];
github tinymce / tinymce / modules / bridge / src / main / ts / ephox / bridge / components / toolbar / ContextToolbar.ts View on Github external
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
  }))
github tinymce / tinymce / modules / bridge / src / main / ts / ephox / bridge / components / toolbar / ContextToolbar.ts View on Github external
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', () =&gt; ''),
  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&gt; =&gt; {
  return ValueSchema.asRaw('ContextToolbar', contextToolbarSchema, spec);
github tinymce / tinymce / modules / alloy / src / main / ts / ephox / alloy / api / behaviour / Behaviour.ts View on Github external
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 =&gt; {
  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 {
github tinymce / tinymce / modules / alloy / src / main / ts / ephox / alloy / api / behaviour / Behaviour.ts View on Github external
apis?: {};
  extra?: {};
  state?: {};
}

const derive = (
  capabilities: Array&gt;
): AlloyBehaviourRecord =&gt; {
  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 =&gt; {
  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?: { };
github tinymce / tinymce / modules / alloy / src / main / ts / ephox / alloy / api / behaviour / Behaviour.ts View on Github external
active?: {};
  apis?: {};
  extra?: {};
  state?: {};
}

const derive = (
  capabilities: Array&gt;
): AlloyBehaviourRecord =&gt; {
  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 =&gt; {
  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?: { };
github tinymce / tinymce / modules / alloy / src / main / ts / ephox / alloy / api / behaviour / Behaviour.ts View on Github external
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 =&gt; {
  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({ });
github tinymce / tinymce / modules / bridge / src / main / ts / ephox / bridge / components / toolbar / ContextToolbar.ts View on Github external
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
});
github tinymce / tinymce / modules / bridge / src / main / ts / ephox / bridge / components / toolbar / ContextToolbar.ts View on Github external
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),