@zipify/wysiwyg 1.0.0-dev.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +18 -0
- package/.eslintrc.js +253 -0
- package/.github/actions/deploy-example/action.yaml +61 -0
- package/.github/actions/lint-css/action.yaml +15 -0
- package/.github/actions/lint-js/action.yaml +22 -0
- package/.github/actions/setup/action.yaml +19 -0
- package/.github/actions/unit-tests/action.yaml +13 -0
- package/.github/actions/unit-tests/jest.config.js +8 -0
- package/.github/dependabot.yaml +17 -0
- package/.github/pull_request_template.md +17 -0
- package/.github/workflows/frontend-ci.yaml +120 -0
- package/.husky/pre-commit +4 -0
- package/.lintstagedrc +12 -0
- package/.release-it.json +6 -0
- package/.stylelintrc +110 -0
- package/README.md +61 -0
- package/babel.config.js +15 -0
- package/ci/example/deploy.sh +25 -0
- package/config/jest/TestEnvironment.js +27 -0
- package/config/jest/matchers/index.js +6 -0
- package/config/jest/matchers/toElementHasStyle.js +27 -0
- package/config/jest/matchers/toVueContainComponent.js +20 -0
- package/config/jest/matchers/toVueContainElement.js +34 -0
- package/config/jest/matchers/toVueContainLazyComponent.js +19 -0
- package/config/jest/matchers/toVueEmpty.js +16 -0
- package/config/jest/matchers/toVuexActionHasBeenDispatched.js +19 -0
- package/config/jest/setupMatchers.js +4 -0
- package/config/jest/setupTests.js +32 -0
- package/config/jest/typing.d.ts +14 -0
- package/config/svgo.js +22 -0
- package/config/webpack/example.config.js +86 -0
- package/config/webpack/loaders/index.js +6 -0
- package/config/webpack/loaders/js-loader.js +5 -0
- package/config/webpack/loaders/style-loader.js +7 -0
- package/config/webpack/loaders/svg-loader.js +4 -0
- package/config/webpack/loaders/vue-loader.js +4 -0
- package/config/webpack/settings.js +9 -0
- package/example/ExampleApp.vue +136 -0
- package/example/example.html +17 -0
- package/example/example.js +19 -0
- package/example/fonts.js +474 -0
- package/example/presets.js +245 -0
- package/example/tooltip/Tooltip.js +241 -0
- package/example/tooltip/TooltipManager.js +132 -0
- package/example/tooltip/index.js +3 -0
- package/example/tooltip/modifiers/TooltipCloseOnScrollModifier.js +73 -0
- package/example/tooltip/modifiers/index.js +1 -0
- package/example/tooltip/tooltip.css +95 -0
- package/jest.config.js +17 -0
- package/lib/Wysiwyg.vue +156 -0
- package/lib/__mocks__/svgMock.js +1 -0
- package/lib/__tests__/utils/NodeFactory.js +67 -0
- package/lib/__tests__/utils/index.js +4 -0
- package/lib/__tests__/utils/setReadonlyProperty.js +9 -0
- package/lib/__tests__/utils/waitAsyncOperation.js +6 -0
- package/lib/__tests__/utils/withComponentContext.js +14 -0
- package/lib/assets/icons.svg +69 -0
- package/lib/components/base/Button.vue +117 -0
- package/lib/components/base/ButtonToggle.vue +40 -0
- package/lib/components/base/FieldLabel.vue +28 -0
- package/lib/components/base/Icon.vue +67 -0
- package/lib/components/base/Modal.vue +116 -0
- package/lib/components/base/NumberField.vue +242 -0
- package/lib/components/base/Range.vue +196 -0
- package/lib/components/base/ScrollView.vue +60 -0
- package/lib/components/base/__tests__/Button.test.js +50 -0
- package/lib/components/base/__tests__/Icon.test.js +56 -0
- package/lib/components/base/__tests__/Modal.test.js +69 -0
- package/lib/components/base/__tests__/Range.test.js +39 -0
- package/lib/components/base/colorPicker/ColorPicker.vue +93 -0
- package/lib/components/base/colorPicker/composables/__tests__/usePickerApi.test.js +81 -0
- package/lib/components/base/colorPicker/composables/index.js +2 -0
- package/lib/components/base/colorPicker/composables/usePickerApi.js +35 -0
- package/lib/components/base/colorPicker/composables/usePickerHotkeys.js +25 -0
- package/lib/components/base/colorPicker/index.js +1 -0
- package/lib/components/base/composables/__tests__/useActivatedListener.test.js +89 -0
- package/lib/components/base/composables/__tests__/useDeselectionLock.test.js +80 -0
- package/lib/components/base/composables/__tests__/useElementRef.test.js +29 -0
- package/lib/components/base/composables/__tests__/useModalToggler.test.js +55 -0
- package/lib/components/base/composables/__tests__/useNumberValue.test.js +153 -0
- package/lib/components/base/composables/__tests__/useScrollView.test.js +43 -0
- package/lib/components/base/composables/__tests__/useTempValue.test.js +38 -0
- package/lib/components/base/composables/index.js +7 -0
- package/lib/components/base/composables/useActivatedListener.js +23 -0
- package/lib/components/base/composables/useDeselectionLock.js +35 -0
- package/lib/components/base/composables/useElementRef.js +5 -0
- package/lib/components/base/composables/useModalToggler.js +58 -0
- package/lib/components/base/composables/useNumberValue.js +53 -0
- package/lib/components/base/composables/useScrollView.js +22 -0
- package/lib/components/base/composables/useTempValue.js +11 -0
- package/lib/components/base/dropdown/Dropdown.vue +88 -0
- package/lib/components/base/dropdown/DropdownActivator.vue +81 -0
- package/lib/components/base/dropdown/DropdownDivider.vue +21 -0
- package/lib/components/base/dropdown/DropdownGroup.vue +55 -0
- package/lib/components/base/dropdown/DropdownMenu.vue +62 -0
- package/lib/components/base/dropdown/DropdownOption.vue +91 -0
- package/lib/components/base/dropdown/__tests__/DropdownActivator.test.js +54 -0
- package/lib/components/base/dropdown/__tests__/DropdownMenu.test.js +67 -0
- package/lib/components/base/dropdown/__tests__/DropdownOption.test.js +81 -0
- package/lib/components/base/dropdown/composables/__tests__/useActiveOptionManager.test.js +41 -0
- package/lib/components/base/dropdown/composables/__tests__/useDropdownEntityTitle.test.js +24 -0
- package/lib/components/base/dropdown/composables/index.js +2 -0
- package/lib/components/base/dropdown/composables/useActiveOptionManager.js +25 -0
- package/lib/components/base/dropdown/composables/useDropdownEntityTitle.js +5 -0
- package/lib/components/base/dropdown/index.js +2 -0
- package/lib/components/base/dropdown/injectionTokens.js +5 -0
- package/lib/components/base/index.js +11 -0
- package/lib/components/index.js +1 -0
- package/lib/components/toolbar/Toolbar.vue +56 -0
- package/lib/components/toolbar/ToolbarDevice.vue +35 -0
- package/lib/components/toolbar/ToolbarDivider.vue +50 -0
- package/lib/components/toolbar/ToolbarFull.vue +94 -0
- package/lib/components/toolbar/ToolbarGroup.vue +18 -0
- package/lib/components/toolbar/ToolbarRow.vue +19 -0
- package/lib/components/toolbar/__tests__/Toolbar.test.js +33 -0
- package/lib/components/toolbar/__tests__/ToolbarDivider.test.js +26 -0
- package/lib/components/toolbar/controls/AlignmentControl.vue +72 -0
- package/lib/components/toolbar/controls/AlignmentDeviceControl.vue +67 -0
- package/lib/components/toolbar/controls/BackgroundColorControl.vue +48 -0
- package/lib/components/toolbar/controls/CaseStyleControl.vue +54 -0
- package/lib/components/toolbar/controls/FontColorControl.vue +48 -0
- package/lib/components/toolbar/controls/FontFamilyControl.vue +96 -0
- package/lib/components/toolbar/controls/FontSizeControl.vue +45 -0
- package/lib/components/toolbar/controls/FontWeightControl.vue +43 -0
- package/lib/components/toolbar/controls/ItalicControl.vue +47 -0
- package/lib/components/toolbar/controls/LineHeightControl.vue +102 -0
- package/lib/components/toolbar/controls/ListControl.vue +86 -0
- package/lib/components/toolbar/controls/RemoveFormatControl.vue +37 -0
- package/lib/components/toolbar/controls/StrikeThroughControl.vue +44 -0
- package/lib/components/toolbar/controls/StylePresetControl.vue +95 -0
- package/lib/components/toolbar/controls/SuperscriptControl.vue +44 -0
- package/lib/components/toolbar/controls/UnderlineControl.vue +44 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentControl.test.js +51 -0
- package/lib/components/toolbar/controls/__tests__/AlignmentDeviceControl.test.js +77 -0
- package/lib/components/toolbar/controls/__tests__/BackgroundColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/CaseStyleControl.test.js +43 -0
- package/lib/components/toolbar/controls/__tests__/FontColorControl.test.js +59 -0
- package/lib/components/toolbar/controls/__tests__/FontFamilyControl.test.js +57 -0
- package/lib/components/toolbar/controls/__tests__/FontSizeControl.test.js +47 -0
- package/lib/components/toolbar/controls/__tests__/FontWeightControl.test.js +45 -0
- package/lib/components/toolbar/controls/__tests__/ItalicControl.test.js +63 -0
- package/lib/components/toolbar/controls/__tests__/LineHeightControl.test.js +120 -0
- package/lib/components/toolbar/controls/__tests__/ListControl.test.js +82 -0
- package/lib/components/toolbar/controls/__tests__/RemoveFormatControl.test.js +34 -0
- package/lib/components/toolbar/controls/__tests__/StrikeThroughControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/StylePresetControl.test.js +129 -0
- package/lib/components/toolbar/controls/__tests__/SuperscriptControl.test.js +44 -0
- package/lib/components/toolbar/controls/__tests__/UnderlineControl.test.js +44 -0
- package/lib/components/toolbar/controls/composables/__tests__/useRecentFonts.test.js +69 -0
- package/lib/components/toolbar/controls/composables/index.js +1 -0
- package/lib/components/toolbar/controls/composables/useRecentFonts.js +18 -0
- package/lib/components/toolbar/controls/index.js +16 -0
- package/lib/components/toolbar/index.js +1 -0
- package/lib/composables/__tests__/__snapshots__/useEditor.test.js.snap +24 -0
- package/lib/composables/__tests__/useEditor.test.js +67 -0
- package/lib/composables/__tests__/useToolbar.test.js +56 -0
- package/lib/composables/index.js +2 -0
- package/lib/composables/useEditor.js +21 -0
- package/lib/composables/useToolbar.js +44 -0
- package/lib/directives/__tests__/outClick.test.js +86 -0
- package/lib/directives/__tests__/tooltip.test.js +39 -0
- package/lib/directives/index.js +2 -0
- package/lib/directives/outClick.js +37 -0
- package/lib/directives/tooltip.js +7 -0
- package/lib/enums/Alignments.js +6 -0
- package/lib/enums/CaseStyles.js +5 -0
- package/lib/enums/Devices.js +15 -0
- package/lib/enums/ListTypes.js +23 -0
- package/lib/enums/NodeTypes.js +12 -0
- package/lib/enums/TextSettings.js +30 -0
- package/lib/enums/index.js +6 -0
- package/lib/extensions/Alignment.js +67 -0
- package/lib/extensions/BackgroundColor.js +28 -0
- package/lib/extensions/CaseStyle.js +36 -0
- package/lib/extensions/DeviceManager.js +16 -0
- package/lib/extensions/FontColor.js +36 -0
- package/lib/extensions/FontFamily.js +62 -0
- package/lib/extensions/FontSize.js +74 -0
- package/lib/extensions/FontStyle.js +62 -0
- package/lib/extensions/FontWeight.js +56 -0
- package/lib/extensions/LineHeight.js +60 -0
- package/lib/extensions/StylePreset.js +168 -0
- package/lib/extensions/Superscript.js +5 -0
- package/lib/extensions/TextDecoration.js +97 -0
- package/lib/extensions/__tests__/Alignment.test.js +107 -0
- package/lib/extensions/__tests__/BackgroundColor.test.js +75 -0
- package/lib/extensions/__tests__/CaseStyle.test.js +58 -0
- package/lib/extensions/__tests__/FontColor.test.js +85 -0
- package/lib/extensions/__tests__/FontFamily.test.js +171 -0
- package/lib/extensions/__tests__/FontSize.test.js +183 -0
- package/lib/extensions/__tests__/FontStyle.test.js +136 -0
- package/lib/extensions/__tests__/FontWeight.test.js +151 -0
- package/lib/extensions/__tests__/LineHeight.test.js +106 -0
- package/lib/extensions/__tests__/StylePreset.test.js +400 -0
- package/lib/extensions/__tests__/TextDecoration.test.js +258 -0
- package/lib/extensions/__tests__/__snapshots__/Alignment.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/BackgroundColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/CaseStyle.test.js.snap +69 -0
- package/lib/extensions/__tests__/__snapshots__/FontColor.test.js.snap +28 -0
- package/lib/extensions/__tests__/__snapshots__/FontFamily.test.js.snap +158 -0
- package/lib/extensions/__tests__/__snapshots__/FontSize.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/FontStyle.test.js.snap +87 -0
- package/lib/extensions/__tests__/__snapshots__/FontWeight.test.js.snap +140 -0
- package/lib/extensions/__tests__/__snapshots__/LineHeight.test.js.snap +29 -0
- package/lib/extensions/__tests__/__snapshots__/StylePreset.test.js.snap +310 -0
- package/lib/extensions/__tests__/__snapshots__/TextDecoration.test.js.snap +206 -0
- package/lib/extensions/core/NodeProcessor.js +32 -0
- package/lib/extensions/core/SelectionProcessor.js +37 -0
- package/lib/extensions/core/TextProcessor.js +57 -0
- package/lib/extensions/core/__tests__/NodeProcessor.test.js +120 -0
- package/lib/extensions/core/__tests__/SelectionProcessor.test.js +78 -0
- package/lib/extensions/core/__tests__/TextProcessor.test.js +61 -0
- package/lib/extensions/core/__tests__/__snapshots__/NodeProcessor.test.js.snap +93 -0
- package/lib/extensions/core/__tests__/__snapshots__/TextProcessor.test.js.snap +43 -0
- package/lib/extensions/core/index.js +17 -0
- package/lib/extensions/core/inputRules/closeDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/closeSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/copyright.js +6 -0
- package/lib/extensions/core/inputRules/ellipsis.js +6 -0
- package/lib/extensions/core/inputRules/emDash.js +6 -0
- package/lib/extensions/core/inputRules/index.js +9 -0
- package/lib/extensions/core/inputRules/openDoubleQuote.js +6 -0
- package/lib/extensions/core/inputRules/openSingleQuote.js +6 -0
- package/lib/extensions/core/inputRules/registeredTrademark.js +6 -0
- package/lib/extensions/core/inputRules/trademark.js +6 -0
- package/lib/extensions/index.js +49 -0
- package/lib/extensions/list/List.js +81 -0
- package/lib/extensions/list/ListItem.js +12 -0
- package/lib/extensions/list/__tests__/List.test.js +130 -0
- package/lib/extensions/list/__tests__/__snapshots__/List.test.js.snap +212 -0
- package/lib/extensions/list/index.js +1 -0
- package/lib/index.js +1 -0
- package/lib/injectionTokens.js +7 -0
- package/lib/models/Font.js +37 -0
- package/lib/models/__tests__/Font.test.js +58 -0
- package/lib/models/index.js +1 -0
- package/lib/services/FavoriteColors.js +6 -0
- package/lib/services/JsonSerializer.js +15 -0
- package/lib/services/Storage.js +49 -0
- package/lib/services/index.js +3 -0
- package/lib/styles/content.css +39 -0
- package/lib/styles/helpers/common.css +3 -0
- package/lib/styles/helpers/offsets.css +3 -0
- package/lib/styles/helpers/text.css +6 -0
- package/lib/styles/main.css +5 -0
- package/lib/styles/variables.css +57 -0
- package/lib/utils/__tests__/__snapshots__/renderInlineSetting.test.js.snap +40 -0
- package/lib/utils/__tests__/capitalize.test.js +11 -0
- package/lib/utils/__tests__/renderInlineSetting.test.js +39 -0
- package/lib/utils/capitalize.js +3 -0
- package/lib/utils/createCommand.js +3 -0
- package/lib/utils/createKeyboardShortcut.js +6 -0
- package/lib/utils/index.js +4 -0
- package/lib/utils/renderInlineSetting.js +17 -0
- package/package.json +75 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zw-dropdown__divider" />
|
|
3
|
+
</template>
|
|
4
|
+
|
|
5
|
+
<script>
|
|
6
|
+
export default {
|
|
7
|
+
name: 'DropdownDivider'
|
|
8
|
+
};
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<style scoped>
|
|
12
|
+
.zw-dropdown__divider {
|
|
13
|
+
padding: 0 var(--zw-offset-sm);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.zw-dropdown__divider::before {
|
|
17
|
+
content: "";
|
|
18
|
+
display: block;
|
|
19
|
+
border-bottom: 1px solid rgb(var(--zw-color-n30));
|
|
20
|
+
}
|
|
21
|
+
</style>
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<div class="zw-dropdown__group">
|
|
3
|
+
<p class="zw-dropdown__group-title">
|
|
4
|
+
{{ groupTitle }}
|
|
5
|
+
</p>
|
|
6
|
+
|
|
7
|
+
<slot name="option" :option="option" v-for="option of group.options">
|
|
8
|
+
<DropdownOption :option="option" />
|
|
9
|
+
</slot>
|
|
10
|
+
</div>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import { toRef } from '@vue/composition-api';
|
|
15
|
+
import DropdownOption from './DropdownOption';
|
|
16
|
+
import { useDropdownEntityTitle } from './composables';
|
|
17
|
+
|
|
18
|
+
export default {
|
|
19
|
+
name: 'DropdownGroup',
|
|
20
|
+
|
|
21
|
+
components: {
|
|
22
|
+
DropdownOption
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
props: {
|
|
26
|
+
group: {
|
|
27
|
+
type: Object,
|
|
28
|
+
required: true
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
setup(props) {
|
|
33
|
+
const groupTitle = useDropdownEntityTitle(toRef(props, 'group'));
|
|
34
|
+
|
|
35
|
+
return { groupTitle };
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
<style scoped>
|
|
41
|
+
.zw-dropdown__group {
|
|
42
|
+
padding-top: var(--zw-offset-xs);
|
|
43
|
+
padding-bottom: var(--zw-offset-xs);
|
|
44
|
+
--zw-option-offset: var(--zw-offset-xs);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.zw-dropdown__group-title {
|
|
48
|
+
color: var(--zw-color-n70);
|
|
49
|
+
font-weight: var(--zw-font-weight-semibold);
|
|
50
|
+
padding-left: var(--zw-offset-sm);
|
|
51
|
+
padding-right: var(--zw-offset-sm);
|
|
52
|
+
margin-top: 0;
|
|
53
|
+
margin-bottom: var(--zw-offset-xs);
|
|
54
|
+
}
|
|
55
|
+
</style>
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ScrollView>
|
|
3
|
+
<div class="zw-dropdown__menu" data-test-selector="dropdownMenu">
|
|
4
|
+
<template v-for="(option, index) of options">
|
|
5
|
+
<template v-if="option.options">
|
|
6
|
+
<DropdownGroup :key="option.id" :group="option">
|
|
7
|
+
<template #option="attrs">
|
|
8
|
+
<slot v-bind="attrs" name="option" />
|
|
9
|
+
</template>
|
|
10
|
+
</DropdownGroup>
|
|
11
|
+
|
|
12
|
+
<DropdownDivider
|
|
13
|
+
:key="option.id + ' divider'"
|
|
14
|
+
v-if="index + 1 !== options.length"
|
|
15
|
+
/>
|
|
16
|
+
</template>
|
|
17
|
+
|
|
18
|
+
<slot name="option" :option="option" v-else>
|
|
19
|
+
<DropdownOption :option="option" />
|
|
20
|
+
</slot>
|
|
21
|
+
</template>
|
|
22
|
+
</div>
|
|
23
|
+
</ScrollView>
|
|
24
|
+
</template>
|
|
25
|
+
|
|
26
|
+
<script>
|
|
27
|
+
import { provide } from '@vue/composition-api';
|
|
28
|
+
import ScrollView from '../ScrollView';
|
|
29
|
+
import { InjectionTokens } from './injectionTokens';
|
|
30
|
+
import DropdownGroup from './DropdownGroup';
|
|
31
|
+
import DropdownOption from './DropdownOption';
|
|
32
|
+
import DropdownDivider from './DropdownDivider';
|
|
33
|
+
|
|
34
|
+
export default {
|
|
35
|
+
name: 'DropdownMenu',
|
|
36
|
+
|
|
37
|
+
components: {
|
|
38
|
+
ScrollView,
|
|
39
|
+
DropdownGroup,
|
|
40
|
+
DropdownOption,
|
|
41
|
+
DropdownDivider
|
|
42
|
+
},
|
|
43
|
+
|
|
44
|
+
props: {
|
|
45
|
+
options: {
|
|
46
|
+
type: Array,
|
|
47
|
+
required: true
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
setup() {
|
|
52
|
+
provide(InjectionTokens.SESSION, {});
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<style>
|
|
58
|
+
.zw-dropdown__menu {
|
|
59
|
+
padding-top: var(--zw-offset-xs);
|
|
60
|
+
padding-bottom: var(--zw-offset-xs);
|
|
61
|
+
}
|
|
62
|
+
</style>
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Button
|
|
3
|
+
class="zw-dropdown__option zw-text--truncate"
|
|
4
|
+
ref="optionRef"
|
|
5
|
+
:class="classes"
|
|
6
|
+
@click="activate"
|
|
7
|
+
>
|
|
8
|
+
<slot>{{ optionTitle }}</slot>
|
|
9
|
+
</Button>
|
|
10
|
+
</template>
|
|
11
|
+
|
|
12
|
+
<script>
|
|
13
|
+
import { computed, inject, nextTick, onMounted, ref, toRef } from '@vue/composition-api';
|
|
14
|
+
import Button from '../Button';
|
|
15
|
+
import { useScrollView } from '../composables';
|
|
16
|
+
import { InjectionTokens } from './injectionTokens';
|
|
17
|
+
import { useDropdownEntityTitle } from './composables';
|
|
18
|
+
|
|
19
|
+
export default {
|
|
20
|
+
name: 'DropdownOption',
|
|
21
|
+
|
|
22
|
+
components: {
|
|
23
|
+
Button
|
|
24
|
+
},
|
|
25
|
+
|
|
26
|
+
props: {
|
|
27
|
+
option: {
|
|
28
|
+
type: Object,
|
|
29
|
+
required: true
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
|
|
33
|
+
setup(props) {
|
|
34
|
+
const activeOptionManager = inject(InjectionTokens.ACTIVE_MANAGER);
|
|
35
|
+
const dropdownToggler = inject(InjectionTokens.TOGGLER);
|
|
36
|
+
const session = inject(InjectionTokens.SESSION);
|
|
37
|
+
|
|
38
|
+
const optionRef = ref(null);
|
|
39
|
+
const scrollView = useScrollView();
|
|
40
|
+
const optionTitle = useDropdownEntityTitle(toRef(props, 'option'));
|
|
41
|
+
const isActive = computed(() => props.option.id === activeOptionManager.activeOption.value?.id);
|
|
42
|
+
const classes = computed(() => ({ 'zw-dropdown__option--active': isActive.value }));
|
|
43
|
+
|
|
44
|
+
function activate() {
|
|
45
|
+
activeOptionManager.activateOption(props.option);
|
|
46
|
+
dropdownToggler.close();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
onMounted(async () => {
|
|
50
|
+
if (isActive.value && !session.scrolled) {
|
|
51
|
+
session.scrolled = true; // Prevent multiple scrolling to option
|
|
52
|
+
|
|
53
|
+
await nextTick();
|
|
54
|
+
const el = optionRef.value.$el;
|
|
55
|
+
const offset = el.offsetHeight * 1.5;
|
|
56
|
+
|
|
57
|
+
scrollView.scrollToElement(el, { offset });
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
return {
|
|
62
|
+
optionTitle,
|
|
63
|
+
classes,
|
|
64
|
+
isActive,
|
|
65
|
+
optionRef,
|
|
66
|
+
activate
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
</script>
|
|
71
|
+
|
|
72
|
+
<style scoped>
|
|
73
|
+
.zw-dropdown__option {
|
|
74
|
+
width: 100%;
|
|
75
|
+
display: block;
|
|
76
|
+
color: rgb(var(--zw-color-white));
|
|
77
|
+
padding-top: var(--zw-offset-xxs);
|
|
78
|
+
padding-right: var(--zw-offset-sm);
|
|
79
|
+
padding-left: calc(var(--zw-offset-sm) + var(--zw-option-offset, 0px));
|
|
80
|
+
padding-bottom: var(--zw-offset-xxs);
|
|
81
|
+
text-align: left;
|
|
82
|
+
transition: 0.1s background-color ease-out;
|
|
83
|
+
will-change: background-color;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.zw-dropdown__option:hover,
|
|
87
|
+
.zw-dropdown__option:focus,
|
|
88
|
+
.zw-dropdown__option--active {
|
|
89
|
+
background-color: rgb(var(--zw-color-n30));
|
|
90
|
+
}
|
|
91
|
+
</style>
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
3
|
+
import DropdownActivator from '../DropdownActivator';
|
|
4
|
+
import { InjectionTokens } from '../injectionTokens';
|
|
5
|
+
import Button from '../../Button';
|
|
6
|
+
|
|
7
|
+
const createToggler = ({ isOpened } = {}) => ({
|
|
8
|
+
isOpened: ref(isOpened ?? false),
|
|
9
|
+
open: jest.fn()
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
const createActiveOptionManager = ({ activeOption } = {}) => ({
|
|
13
|
+
activeOption: ref(activeOption ?? { id: 'test' })
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
function createComponent({ toggler, activeOptionManager } = {}) {
|
|
17
|
+
return shallowMount(DropdownActivator, {
|
|
18
|
+
provide: {
|
|
19
|
+
[InjectionTokens.TOGGLER]: toggler ?? createToggler(),
|
|
20
|
+
[InjectionTokens.ACTIVE_MANAGER]: activeOptionManager ?? createActiveOptionManager()
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
describe('rendering', () => {
|
|
26
|
+
test('should render active state', () => {
|
|
27
|
+
const toggler = createToggler({ isOpened: true });
|
|
28
|
+
const wrapper = createComponent({ toggler });
|
|
29
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
30
|
+
|
|
31
|
+
expect(buttonWrapper.props('active')).toBe(true);
|
|
32
|
+
expect(buttonWrapper.classes('zw-dropdown__activator--active')).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
test('should render inactive state', () => {
|
|
36
|
+
const toggler = createToggler({ isOpened: false });
|
|
37
|
+
const wrapper = createComponent({ toggler });
|
|
38
|
+
const buttonWrapper = wrapper.findComponent(Button);
|
|
39
|
+
|
|
40
|
+
expect(buttonWrapper.props('active')).toBe(false);
|
|
41
|
+
expect(buttonWrapper.classes('zw-dropdown__activator--active')).toBeFalsy();
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
describe('open dropdown', () => {
|
|
46
|
+
test('should open menu', () => {
|
|
47
|
+
const toggler = createToggler();
|
|
48
|
+
const wrapper = createComponent({ toggler });
|
|
49
|
+
|
|
50
|
+
wrapper.findComponent(Button).vm.$emit('click');
|
|
51
|
+
|
|
52
|
+
expect(toggler.open).toHaveBeenCalled();
|
|
53
|
+
});
|
|
54
|
+
});
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
3
|
+
import { InjectionTokens } from '../injectionTokens';
|
|
4
|
+
import DropdownMenu from '../DropdownMenu';
|
|
5
|
+
|
|
6
|
+
const createToggler = (isOpened) => ({
|
|
7
|
+
close: jest.fn(),
|
|
8
|
+
isOpened: ref(isOpened ?? true)
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
function createComponent({ options, toggler } = {}) {
|
|
12
|
+
return shallowMount(DropdownMenu, {
|
|
13
|
+
stubs: {
|
|
14
|
+
transition: {
|
|
15
|
+
render() {
|
|
16
|
+
return this.$slots.default?.[0];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
propsData: {
|
|
21
|
+
options: options ?? []
|
|
22
|
+
},
|
|
23
|
+
provide: {
|
|
24
|
+
[InjectionTokens.TOGGLER]: toggler ?? createToggler()
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const SELECTORS = {
|
|
30
|
+
MENU: '[data-test-selector="dropdownMenu"]'
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe('rendering', () => {
|
|
34
|
+
const getChildEls = (wrapper) => Array.from(wrapper.element.children);
|
|
35
|
+
const getChildTagNames = (wrapper) => getChildEls(wrapper).map((el) => el.tagName);
|
|
36
|
+
|
|
37
|
+
test('should render plain options', () => {
|
|
38
|
+
const wrapper = createComponent({
|
|
39
|
+
options: [
|
|
40
|
+
{ id: 'one' },
|
|
41
|
+
{ id: 'two' }
|
|
42
|
+
]
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
const menuWrapper = wrapper.find(SELECTORS.MENU);
|
|
46
|
+
const childTagNames = getChildTagNames(menuWrapper);
|
|
47
|
+
|
|
48
|
+
expect(childTagNames).toEqual(['DROPDOWNOPTION-STUB', 'DROPDOWNOPTION-STUB']);
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
test('should render groups options', () => {
|
|
52
|
+
const wrapper = createComponent({
|
|
53
|
+
options: [
|
|
54
|
+
{ id: 'one', options: [] },
|
|
55
|
+
{ id: 'two', options: [] }
|
|
56
|
+
]
|
|
57
|
+
});
|
|
58
|
+
const menuWrapper = wrapper.find(SELECTORS.MENU);
|
|
59
|
+
const childTagNames = getChildTagNames(menuWrapper);
|
|
60
|
+
|
|
61
|
+
expect(childTagNames).toEqual([
|
|
62
|
+
'DROPDOWNGROUP-STUB',
|
|
63
|
+
'DROPDOWNDIVIDER-STUB',
|
|
64
|
+
'DROPDOWNGROUP-STUB'
|
|
65
|
+
]);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { shallowMount } from '@vue/test-utils';
|
|
2
|
+
import { ref } from '@vue/composition-api';
|
|
3
|
+
import DropdownOption from '../DropdownOption';
|
|
4
|
+
import { InjectionTokens } from '../injectionTokens';
|
|
5
|
+
import Button from '../../Button';
|
|
6
|
+
import { SCROLL_VIEW } from '../../composables';
|
|
7
|
+
|
|
8
|
+
const createActiveManager = ({ activeOption } = {}) => ({
|
|
9
|
+
activeOption: ref(activeOption ?? { id: '123' }),
|
|
10
|
+
activateOption: jest.fn()
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const createToggler = () => ({
|
|
14
|
+
isOpened: ref(true),
|
|
15
|
+
close: jest.fn()
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
function createComponent({ option, activeManager, toggler }) {
|
|
19
|
+
return shallowMount(DropdownOption, {
|
|
20
|
+
propsData: { option },
|
|
21
|
+
|
|
22
|
+
provide: {
|
|
23
|
+
[InjectionTokens.ACTIVE_MANAGER]: activeManager ?? createActiveManager(),
|
|
24
|
+
[InjectionTokens.TOGGLER]: toggler ?? createToggler(),
|
|
25
|
+
[InjectionTokens.SESSION]: {},
|
|
26
|
+
[SCROLL_VIEW]: ref(null)
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
describe('rendering', () => {
|
|
32
|
+
test('should render active state', () => {
|
|
33
|
+
const wrapper = createComponent({
|
|
34
|
+
option: { id: 1 },
|
|
35
|
+
|
|
36
|
+
activeManager: createActiveManager({
|
|
37
|
+
activeOption: { id: 1 }
|
|
38
|
+
})
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
expect(wrapper.classes('zw-dropdown__option--active')).toBeTruthy();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
test('should render inactive state', () => {
|
|
45
|
+
const wrapper = createComponent({
|
|
46
|
+
option: { id: 1 },
|
|
47
|
+
|
|
48
|
+
activeManager: createActiveManager({
|
|
49
|
+
activeOption: { id: 2 }
|
|
50
|
+
})
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
expect(wrapper.classes('zw-dropdown__option--active')).toBeFalsy();
|
|
54
|
+
});
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
describe('should activate', () => {
|
|
58
|
+
test('should activate option', () => {
|
|
59
|
+
const activeManager = createActiveManager();
|
|
60
|
+
const wrapper = createComponent({
|
|
61
|
+
option: { id: 1 },
|
|
62
|
+
activeManager
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
wrapper.findComponent(Button).vm.$emit('click');
|
|
66
|
+
|
|
67
|
+
expect(activeManager.activateOption).toHaveBeenCalled();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('should close dropdown', () => {
|
|
71
|
+
const toggler = createToggler();
|
|
72
|
+
const wrapper = createComponent({
|
|
73
|
+
option: { id: 1 },
|
|
74
|
+
toggler
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
wrapper.findComponent(Button).vm.$emit('click');
|
|
78
|
+
|
|
79
|
+
expect(toggler.close).toHaveBeenCalled();
|
|
80
|
+
});
|
|
81
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { nextTick, ref } from '@vue/composition-api';
|
|
2
|
+
import { useActiveOptionManager } from '../useActiveOptionManager';
|
|
3
|
+
|
|
4
|
+
describe('manage active option', () => {
|
|
5
|
+
test('should find initial option by id', () => {
|
|
6
|
+
const manager = useActiveOptionManager({
|
|
7
|
+
optionsRef: ref([{ id: 'test' }]),
|
|
8
|
+
inputRef: ref('test'),
|
|
9
|
+
onChange: () => {}
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
expect(manager.activeOption.value).toEqual({ id: 'test' });
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
test('should update active option on prop change', async () => {
|
|
16
|
+
const inputRef = ref('test');
|
|
17
|
+
const manager = useActiveOptionManager({
|
|
18
|
+
optionsRef: ref([{ id: 'test' }, { id: 'new' }]),
|
|
19
|
+
inputRef,
|
|
20
|
+
onChange: () => {}
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
inputRef.value = 'new';
|
|
24
|
+
await nextTick();
|
|
25
|
+
|
|
26
|
+
expect(manager.activeOption.value).toEqual({ id: 'new' });
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
test('should activate option', () => {
|
|
30
|
+
const onChange = jest.fn();
|
|
31
|
+
const manager = useActiveOptionManager({
|
|
32
|
+
optionsRef: ref([{ id: 'test' }, { id: 'new' }]),
|
|
33
|
+
inputRef: ref('test'),
|
|
34
|
+
onChange
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
manager.activateOption({ id: 'new' });
|
|
38
|
+
|
|
39
|
+
expect(onChange).toHaveBeenCalledWith({ id: 'new' });
|
|
40
|
+
});
|
|
41
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ref } from '@vue/composition-api';
|
|
2
|
+
import { useDropdownEntityTitle } from '../useDropdownEntityTitle';
|
|
3
|
+
|
|
4
|
+
describe('resolve title', () => {
|
|
5
|
+
test('should get title if present', () => {
|
|
6
|
+
const entity = ref({ id: 'id', title: 'title' });
|
|
7
|
+
const entityTitle = useDropdownEntityTitle(entity);
|
|
8
|
+
|
|
9
|
+
expect(entityTitle.value).toBe('title');
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
test('should get id if no title', () => {
|
|
13
|
+
const entity = ref({ id: 'id' });
|
|
14
|
+
const entityTitle = useDropdownEntityTitle(entity);
|
|
15
|
+
|
|
16
|
+
expect(entityTitle.value).toBe('id');
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('should return empty if no active entity', () => {
|
|
20
|
+
const entityTitle = useDropdownEntityTitle(ref(null));
|
|
21
|
+
|
|
22
|
+
expect(entityTitle.value).toBe('');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { ref, watch } from '@vue/composition-api';
|
|
2
|
+
|
|
3
|
+
export function useActiveOptionManager({ optionsRef, inputRef, stateless, onChange }) {
|
|
4
|
+
const activeOption = ref(null);
|
|
5
|
+
|
|
6
|
+
function activateOption(option, { emitEvent } = {}) {
|
|
7
|
+
if (!stateless) activeOption.value = option;
|
|
8
|
+
if (emitEvent !== false) onChange(option);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function activateById(id, params) {
|
|
12
|
+
const option = optionsRef.value
|
|
13
|
+
.flatMap((option) => option.options || option)
|
|
14
|
+
.find((option) => option.id === id);
|
|
15
|
+
|
|
16
|
+
activateOption(option, params);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
const syncInputValue = () => activateById(inputRef.value, { emitEvent: false });
|
|
20
|
+
|
|
21
|
+
syncInputValue();
|
|
22
|
+
watch(inputRef, syncInputValue);
|
|
23
|
+
|
|
24
|
+
return { activeOption, activateOption };
|
|
25
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default as Button } from './Button';
|
|
2
|
+
export { default as ButtonToggle } from './ButtonToggle';
|
|
3
|
+
export { default as Icon } from './Icon';
|
|
4
|
+
export { default as ScrollView } from './ScrollView';
|
|
5
|
+
export { default as FieldLabel } from './FieldLabel';
|
|
6
|
+
export { default as Range } from './Range';
|
|
7
|
+
export { default as NumberField } from './NumberField';
|
|
8
|
+
export { default as Modal } from './Modal';
|
|
9
|
+
export { useModalToggler } from './composables';
|
|
10
|
+
export * from './dropdown';
|
|
11
|
+
export * from './colorPicker';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './toolbar';
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<Transition name="zw-toolbar-" :duration="800">
|
|
3
|
+
<div class="zw-toolbar">
|
|
4
|
+
<component :is="toolbarComponent" />
|
|
5
|
+
</div>
|
|
6
|
+
</Transition>
|
|
7
|
+
</template>
|
|
8
|
+
|
|
9
|
+
<script>
|
|
10
|
+
import { computed } from '@vue/composition-api';
|
|
11
|
+
import { Devices } from '../../enums';
|
|
12
|
+
import ToolbarFull from './ToolbarFull';
|
|
13
|
+
import ToolbarDevice from './ToolbarDevice';
|
|
14
|
+
|
|
15
|
+
export default {
|
|
16
|
+
name: 'Toolbar',
|
|
17
|
+
|
|
18
|
+
props: {
|
|
19
|
+
device: {
|
|
20
|
+
type: String,
|
|
21
|
+
required: true
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
|
|
25
|
+
setup(props) {
|
|
26
|
+
const toolbarComponent = computed(() => {
|
|
27
|
+
return props.device === Devices.DESKTOP ? ToolbarFull : ToolbarDevice;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { toolbarComponent };
|
|
31
|
+
}
|
|
32
|
+
};
|
|
33
|
+
</script>
|
|
34
|
+
|
|
35
|
+
<style scoped>
|
|
36
|
+
.zw-toolbar {
|
|
37
|
+
border-radius: 2px;
|
|
38
|
+
background-color: rgb(var(--zw-color-n15));
|
|
39
|
+
color: rgb(var(--zw-color-n70));
|
|
40
|
+
z-index: 999;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.zw-toolbar--enter-active,
|
|
44
|
+
.zw-toolbar--leave-active {
|
|
45
|
+
transition: opacity 0.15s ease-out;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.zw-toolbar--leave-active {
|
|
49
|
+
transition: opacity 0s ease-in;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
.zw-toolbar--enter,
|
|
53
|
+
.zw-toolbar--leave-to {
|
|
54
|
+
opacity: 0;
|
|
55
|
+
}
|
|
56
|
+
</style>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
<template>
|
|
2
|
+
<ToolbarRow>
|
|
3
|
+
<StylePresetControl />
|
|
4
|
+
<ToolbarDivider vertical />
|
|
5
|
+
<AlignmentDeviceControl />
|
|
6
|
+
<ToolbarDivider vertical />
|
|
7
|
+
<FontSizeControl />
|
|
8
|
+
<ToolbarDivider vertical />
|
|
9
|
+
<LineHeightControl />
|
|
10
|
+
</ToolbarRow>
|
|
11
|
+
</template>
|
|
12
|
+
|
|
13
|
+
<script>
|
|
14
|
+
import ToolbarRow from './ToolbarRow';
|
|
15
|
+
import ToolbarDivider from './ToolbarDivider';
|
|
16
|
+
import {
|
|
17
|
+
StylePresetControl,
|
|
18
|
+
AlignmentDeviceControl,
|
|
19
|
+
FontSizeControl,
|
|
20
|
+
LineHeightControl
|
|
21
|
+
} from './controls';
|
|
22
|
+
|
|
23
|
+
export default {
|
|
24
|
+
name: 'ToolbarDevice',
|
|
25
|
+
|
|
26
|
+
components: {
|
|
27
|
+
ToolbarRow,
|
|
28
|
+
ToolbarDivider,
|
|
29
|
+
StylePresetControl,
|
|
30
|
+
AlignmentDeviceControl,
|
|
31
|
+
FontSizeControl,
|
|
32
|
+
LineHeightControl
|
|
33
|
+
}
|
|
34
|
+
};
|
|
35
|
+
</script>
|