OXIESEC PANEL
- Current Dir:
/
/
var
/
www
/
reader
/
_backup
/
tinymce
/
tinymce
/
src
/
themes
/
silver
/
main
/
ts
/
ui
/
dialog
Server IP: 139.59.38.164
Upload:
Create Dir:
Name
Size
Modified
Perms
📁
..
-
02/20/2020 06:40:48 AM
rwxr-xr-x
📄
AlertDialog.ts
1.7 KB
02/20/2020 06:38:15 AM
rw-r--r--
📄
Autocomplete.ts
1.78 KB
02/20/2020 06:38:15 AM
rw-r--r--
📄
Bar.ts
689 bytes
02/20/2020 06:38:16 AM
rw-r--r--
📄
BodyPanel.ts
2.11 KB
02/20/2020 06:38:16 AM
rw-r--r--
📄
Collection.ts
5.65 KB
02/20/2020 06:38:17 AM
rw-r--r--
📄
ColorInput.ts
5.81 KB
02/20/2020 06:38:17 AM
rw-r--r--
📄
ColorPicker.ts
4.06 KB
02/20/2020 06:38:19 AM
rw-r--r--
📄
ConfirmDialog.ts
2.13 KB
02/20/2020 06:38:19 AM
rw-r--r--
📄
CustomEditor.ts
2.04 KB
02/20/2020 06:38:20 AM
rw-r--r--
📄
Dialogs.ts
3.91 KB
02/20/2020 06:38:20 AM
rw-r--r--
📄
Dropzone.ts
4.89 KB
02/20/2020 06:38:21 AM
rw-r--r--
📄
Grid.ts
735 bytes
02/20/2020 06:38:21 AM
rw-r--r--
📄
IFrame.ts
3.3 KB
02/20/2020 06:38:22 AM
rw-r--r--
📄
Label.ts
1.29 KB
02/20/2020 06:38:22 AM
rw-r--r--
📄
SelectBox.ts
2.37 KB
02/20/2020 06:38:23 AM
rw-r--r--
📄
SizeInput.ts
4.96 KB
02/20/2020 06:38:23 AM
rw-r--r--
📄
TabPanel.ts
5.41 KB
02/20/2020 06:38:24 AM
rw-r--r--
📄
Table.ts
1.52 KB
02/20/2020 06:38:24 AM
rw-r--r--
📄
TextField.ts
4.24 KB
02/20/2020 06:38:25 AM
rw-r--r--
📄
TypeAheadInput.ts
1.31 KB
02/20/2020 06:38:26 AM
rw-r--r--
📄
UrlInput.ts
9.25 KB
02/20/2020 06:38:26 AM
rw-r--r--
📄
WindowManager.ts
6.3 KB
02/20/2020 06:38:27 AM
rw-r--r--
📁
imagetools
-
02/20/2020 06:42:42 AM
rwxr-xr-x
Editing: ColorInput.ts
Close
/** * Copyright (c) Tiny Technologies, Inc. All rights reserved. * Licensed under the LGPL or a commercial license. * For LGPL see License.txt in the project root for license information. * For commercial licenses see https://www.tiny.cloud/ */ import { AddEventsBehaviour, AlloyEvents, AlloySpec, AlloyTriggers, Behaviour, Composing, CustomEvent, Focusing, FormField, Input, Invalidating, Layout, Memento, Representing, SimpleSpec, Tabstopping, } from '@ephox/alloy'; import { Types } from '@ephox/bridge'; import { Future, Id, Option, Result } from '@ephox/katamari'; import { Css, Element, Traverse } from '@ephox/sugar'; import { UiFactoryBackstageShared } from '../../backstage/Backstage'; import { UiFactoryBackstageForColorInput } from '../../backstage/ColorInputBackstage'; import { renderLabel } from '../alien/FieldLabeller'; import ColorSwatch from '../core/color/ColorSwatch'; import Settings from '../core/color/Settings'; import { renderPanelButton } from '../general/PanelButton'; const colorInputChangeEvent = Id.generate('color-input-change'); const colorSwatchChangeEvent = Id.generate('color-swatch-change'); const colorPickerCancelEvent = Id.generate('color-picker-cancel'); interface ColorInputChangeEvent extends CustomEvent { color: () => string; } interface ColorSwatchChangeEvent extends CustomEvent { value: () => string; } interface ColorPickerCancelEvent extends CustomEvent { value: () => string; } export const renderColorInput = (spec: Types.ColorInput.ColorInput, sharedBackstage: UiFactoryBackstageShared, colorInputBackstage: UiFactoryBackstageForColorInput): SimpleSpec => { const pField = FormField.parts().field({ factory: Input, inputClasses: ['tox-textfield'], onSetValue: (c) => Invalidating.run(c).get(() => { }), inputBehaviours: Behaviour.derive([ Tabstopping.config({ }), Invalidating.config({ invalidClass: 'tox-textbox-field-invalid', getRoot: (comp) => { return Traverse.parent(comp.element()); }, notify: { onValid: (comp) => { // onValid should pass through the value here // We need a snapshot of the value validated. const val = Representing.getValue(comp); AlloyTriggers.emitWith(comp, colorInputChangeEvent, { color: val }); } }, validator: { validateOnLoad: false, validate: (input) => { const inputValue = Representing.getValue(input); // Consider empty strings valid colours if (inputValue.length === 0) { return Future.pure(Result.value(true)); } else { const span = Element.fromTag('span'); Css.set(span, 'background-color', inputValue); const res = Css.getRaw(span, 'background-color').fold( // TODO: Work out what we want to do here. () => Result.error('blah'), (_) => Result.value(inputValue) ); return Future.pure(res); } } } }) ]), selectOnFocus: false }); const pLabel: Option<AlloySpec> = spec.label.map((label) => renderLabel(label, sharedBackstage.providers)); const emitSwatchChange = (colorBit, value) => { AlloyTriggers.emitWith(colorBit, colorSwatchChangeEvent, { value }); }; const onItemAction = (value) => { sharedBackstage.getSink().each((sink) => { memColorButton.getOpt(sink).each((colorBit) => { if (value === 'custom') { colorInputBackstage.colorPicker((valueOpt) => { valueOpt.fold( () => AlloyTriggers.emit(colorBit, colorPickerCancelEvent), (value) => { emitSwatchChange(colorBit, value); Settings.addColor(value); } ); }, '#ffffff'); } else if (value === 'remove') { emitSwatchChange(colorBit, ''); } else { emitSwatchChange(colorBit, value); } }); }); }; const memColorButton = Memento.record( renderPanelButton({ dom: { tag: 'span', attributes: { 'aria-label': sharedBackstage.providers.translate('Color swatch') } }, layouts: Option.some({ onRtl: () => [ Layout.southeast ], onLtr: () => [ Layout.southwest ] }), components: [], fetch: ColorSwatch.getFetch(colorInputBackstage.getColors(), colorInputBackstage.hasCustomColors()), onItemAction }, sharedBackstage) ); return FormField.sketch({ dom: { tag: 'div', classes: ['tox-form__group'] }, components: pLabel.toArray().concat([ { dom: { tag: 'div', classes: ['tox-color-input'] }, components: [ pField, memColorButton.asSpec() ] } ]), fieldBehaviours: Behaviour.derive([ AddEventsBehaviour.config('form-field-events', [ AlloyEvents.run<ColorInputChangeEvent>(colorInputChangeEvent, (comp, se) => { memColorButton.getOpt(comp).each((colorButton) => { Css.set(colorButton.element(), 'background-color', se.event().color()); }); }), AlloyEvents.run<ColorSwatchChangeEvent>(colorSwatchChangeEvent, (comp, se) => { FormField.getField(comp).each((field) => { Representing.setValue(field, se.event().value()); // Focus the field now that we've set its value Composing.getCurrent(comp).each(Focusing.focus); }); }), AlloyEvents.run<ColorPickerCancelEvent>(colorPickerCancelEvent, (comp, se) => { FormField.getField(comp).each((field) => { Composing.getCurrent(comp).each(Focusing.focus); }); }) ]) ]) }); };