@madgex/design-system-ce 5.2.0 → 5.4.0

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/.eslintrc.js CHANGED
@@ -1,7 +1,14 @@
1
1
  module.exports = {
2
- extends: ['plugin:vue/essential', '@vue/prettier'],
3
- rules: {},
4
2
  env: {
5
3
  browser: true,
6
4
  },
5
+ extends: ['eslint:recommended', 'plugin:vue/vue3-recommended', 'prettier'],
6
+ rules: {
7
+ 'vue/no-v-html': 0,
8
+ 'no-debugger': 0,
9
+ 'vue/singleline-html-element-content-newline': 'off',
10
+ 'vue/multiline-html-element-content-newline': 'off',
11
+ 'vue/html-indent': 'off',
12
+ 'vue/html-self-closing': ['error', { html: { void: 'any' } }],
13
+ },
7
14
  };
package/CHANGELOG.md CHANGED
@@ -3,6 +3,42 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [5.4.0](https://github.com/projects/MDS/repos/mds-branding/compare/diff?targetBranch=refs/tags/@madgex/design-system-ce@5.3.0&sourceBranch=refs/tags/@madgex/design-system-ce@5.4.0) (2023-01-05)
7
+
8
+
9
+ ### Features
10
+
11
+ * CE combobox default enter key action if not expanded ([c1d7329](https://github.com/projects/MDS/repos/mds-branding/commits/c1d732995c364c7310522f4ca1f87e6466acd08a))
12
+
13
+
14
+
15
+ ## [5.3.0](https://github.com/projects/MDS/repos/mds-branding/compare/diff?targetBranch=refs/tags/@madgex/design-system-ce@5.2.0&sourceBranch=refs/tags/@madgex/design-system-ce@5.3.0) (2022-11-25)
16
+
17
+
18
+ ### Features
19
+
20
+ * add link for text editor ([288ad29](https://github.com/projects/MDS/repos/mds-branding/commits/288ad2988076cebddeebab420e3e5438a5d2f818))
21
+
22
+
23
+ ### Bug Fixes
24
+
25
+ * automatically apply protocol to textEditor link ([fee5fc7](https://github.com/projects/MDS/repos/mds-branding/commits/fee5fc760d7fc3e01f3bff56022b5fd942cb6d44))
26
+ * remove link editor popover/button ([db6c5f8](https://github.com/projects/MDS/repos/mds-branding/commits/db6c5f8bb64d2a2d44a5ce13b7f4d943664a7aad))
27
+ * remove link editor popover/button ([0b263f8](https://github.com/projects/MDS/repos/mds-branding/commits/0b263f824e7deebd74655aa990e5c1c9e771b831))
28
+ * remove unused code ([b29e960](https://github.com/projects/MDS/repos/mds-branding/commits/b29e96030d7f53242d65335022a2b0af49fff733))
29
+ * texteditor anchor validation ([5e40b46](https://github.com/projects/MDS/repos/mds-branding/commits/5e40b462974a26473d36c2b033de4d1eb606c368))
30
+ * texteditor applyMissingProtocol mailto ([af94428](https://github.com/projects/MDS/repos/mds-branding/commits/af944282bc8f2aa239031a09310112cf0d153924))
31
+ * textEditor link enabled if valid selection ([654dc8d](https://github.com/projects/MDS/repos/mds-branding/commits/654dc8d61d1846e684d3c3cd3b88b84d011cbc87))
32
+ * textEditor link popover spacing ([2236c64](https://github.com/projects/MDS/repos/mds-branding/commits/2236c6442261f05dee13ab82319bc503d9262832))
33
+ * textEditor links always underline ([d7851e3](https://github.com/projects/MDS/repos/mds-branding/commits/d7851e355b1e8dcbbf4c75c6ad8eac8b6c60ed44))
34
+ * textEditor linkUrl i18n, for/id couple ([2cdad01](https://github.com/projects/MDS/repos/mds-branding/commits/2cdad0129cbc5354441ebf1830a7324559386533))
35
+ * textEditor remove auto-focus on open link editor ([1c42419](https://github.com/projects/MDS/repos/mds-branding/commits/1c42419ced20efe5bb0cb1e80221eab509b29645))
36
+ * textEditori18n ([6bf5d03](https://github.com/projects/MDS/repos/mds-branding/commits/6bf5d0352ce1ec77908c03a9e597d8ddbc7f3ba9))
37
+ * textEdtorPopover ([13c39be](https://github.com/projects/MDS/repos/mds-branding/commits/13c39bee9c0d676fa87bf815c64873b92ba9ee7e))
38
+ * tweak text editor link ([32e3992](https://github.com/projects/MDS/repos/mds-branding/commits/32e399236782169c3075a4a2ebc853c6a690f966))
39
+
40
+
41
+
6
42
  ## [5.2.0](https://github.com/projects/MDS/repos/mds-branding/compare/diff?targetBranch=refs/tags/@madgex/design-system-ce@5.1.2&sourceBranch=refs/tags/@madgex/design-system-ce@5.2.0) (2022-08-18)
7
43
 
8
44
 
@@ -7,7 +7,7 @@
7
7
  @keydown.home="hiddenGuard(onKeyHome)"
8
8
  @keydown.end="hiddenGuard(onKeyEnd)"
9
9
  @keydown.esc="makeInactive"
10
- @keydown.enter.stop.prevent="chooseOption"
10
+ @keydown.enter="handleKeyDownEnter"
11
11
  >
12
12
  <input
13
13
  @input="handleInput"
@@ -248,6 +248,13 @@ export default {
248
248
  this.chosenOption = option;
249
249
  this.makeInactive();
250
250
  },
251
+ /* When expanded then enter key down selects an option, otherwise enter key will be native behaviour, eg submit form */
252
+ handleKeyDownEnter(event) {
253
+ if (this.expanded) {
254
+ event.preventDefault();
255
+ this.chooseOption();
256
+ }
257
+ },
251
258
  chooseOption() {
252
259
  this.chosenOption = this.selectedOption;
253
260
  this.makeInactive();
@@ -13,6 +13,14 @@ export default {
13
13
  components: {
14
14
  TextEditorContent,
15
15
  },
16
+ provide() {
17
+ return {
18
+ iconPath: this.iconpath,
19
+ id: this.editorid,
20
+ customMenuButtons: this.customMenuButtons,
21
+ i18nText: this.i18nText,
22
+ };
23
+ },
16
24
  props: {
17
25
  editorid: {
18
26
  type: String,
@@ -45,21 +53,16 @@ export default {
45
53
  return this.menuButtons ? JSON.parse(this.menuButtons) : null;
46
54
  },
47
55
  i18nText() {
48
- return this.i18n
49
- ? JSON.parse(this.i18n)
50
- : {
51
- toolbarLabel: 'Text formatting',
52
- };
56
+ const parsedI18n = this.i18n ? JSON.parse(this.i18n) : {};
57
+ return {
58
+ toolbarLabel: 'Text formatting',
59
+ addLink: 'Add link',
60
+ removeLink: 'Remove link',
61
+ visuallyHiddenLinkUrlLabel: 'Link url',
62
+ ...parsedI18n,
63
+ };
53
64
  },
54
65
  },
55
- provide() {
56
- return {
57
- iconPath: this.iconpath,
58
- id: this.editorid,
59
- customMenuButtons: this.customMenuButtons,
60
- i18nText: this.i18nText,
61
- };
62
- },
63
66
  mounted() {
64
67
  const fallback = document.querySelector(`#text-editor-fallback-${this.editorid}`);
65
68
  if (fallback) fallback.remove();
@@ -8,6 +8,7 @@
8
8
  <script>
9
9
  import StarterKit from '@tiptap/starter-kit';
10
10
  import { Editor, EditorContent } from '@tiptap/vue-3';
11
+ import Link from '@tiptap/extension-link';
11
12
  import TextEditorToolbar from './TextEditorToolbar.vue';
12
13
 
13
14
  export default {
@@ -46,7 +47,13 @@ export default {
46
47
 
47
48
  mounted() {
48
49
  this.editor = new Editor({
49
- extensions: [StarterKit],
50
+ extensions: [
51
+ StarterKit,
52
+ Link.configure({
53
+ protocols: ['http', 'https', 'mailto'], // automatically create links of text with these protocols
54
+ openOnClick: false,
55
+ }),
56
+ ],
50
57
  editorProps: {
51
58
  attributes: {
52
59
  class: 'mds-text-editor__content mds-edited-text',
@@ -0,0 +1,113 @@
1
+ <template>
2
+ <div ref="popperRef" class="mds-popover" :class="{ 'mds-popover--active': visible }" :aria-hidden="!visible">
3
+ <div class="mds-popover__arrow" data-popper-arrow />
4
+ <div class="mds-tooltip__inner">
5
+ <slot />
6
+ </div>
7
+ </div>
8
+ </template>
9
+
10
+ <script setup>
11
+ import { onMounted, onUnmounted, ref, watch } from 'vue';
12
+ import { createPopper } from '@popperjs/core';
13
+ import { isNodeSelection, posToDOMRect } from '@tiptap/core';
14
+
15
+ // eslint-disable-next-line no-undef
16
+ const props = defineProps({
17
+ editor: {
18
+ type: Object,
19
+ required: true,
20
+ },
21
+ id: {
22
+ type: String,
23
+ required: true,
24
+ },
25
+ visible: {
26
+ type: Boolean,
27
+ default: false,
28
+ },
29
+ });
30
+
31
+ // eslint-disable-next-line no-undef
32
+ const emit = defineEmits(['update:visible']);
33
+
34
+ const popperRef = ref(null);
35
+ const instance = ref(undefined);
36
+
37
+ const baseSize = 4;
38
+
39
+ const destroy = () => {
40
+ instance.value?.destroy();
41
+ instance.value = undefined;
42
+ };
43
+
44
+ const virtualElement = {
45
+ getBoundingClientRect: () => {
46
+ const { view, state } = props.editor;
47
+ const { ranges } = state.selection;
48
+ const from = Math.min(...ranges.map((range) => range.$from.pos));
49
+ const to = Math.max(...ranges.map((range) => range.$to.pos));
50
+ if (isNodeSelection(state.selection)) {
51
+ const node = view.nodeDOM(from);
52
+ if (node) return node.getBoundingClientRect();
53
+ }
54
+ return posToDOMRect(view, from, to);
55
+ },
56
+ };
57
+
58
+ const initPopper = () => {
59
+ if (instance.value) destroy();
60
+ if (!popperRef.value) return;
61
+ instance.value = createPopper(virtualElement, popperRef.value, {
62
+ placement: 'bottom',
63
+ strategy: 'fixed',
64
+ modifiers: [
65
+ { name: 'offset', options: { offset: [0, baseSize * 3] } },
66
+ // arrow will always be at least 5px away from the edge
67
+ { name: 'arrow', options: { padding: 5 } },
68
+ ],
69
+ });
70
+ };
71
+
72
+ const hideMouseDown = (event) => {
73
+ if (!popperRef.value?.contains(event.target) && props.visible) {
74
+ console.log('visiblevisible');
75
+
76
+ emit('update:visible', false);
77
+ }
78
+ };
79
+ const hideKeyDown = (event) => {
80
+ if (event.keyCode === 27) {
81
+ emit('update:visible', false);
82
+ }
83
+ };
84
+
85
+ const updateInstance = () => instance.value?.update();
86
+ const onEditorFocus = () => {
87
+ emit('update:visible', false);
88
+ };
89
+ watch(
90
+ () => props.visible,
91
+ (val) => {
92
+ if (val) {
93
+ updateInstance();
94
+ }
95
+ }
96
+ );
97
+
98
+ onMounted(() => {
99
+ initPopper();
100
+ props.editor.on('focus', onEditorFocus);
101
+ props.editor.on('blur', updateInstance);
102
+ document.addEventListener('mousedown', hideMouseDown);
103
+ document.addEventListener('keydown', hideKeyDown);
104
+ });
105
+
106
+ onUnmounted(() => {
107
+ props.editor.off('focus', onEditorFocus);
108
+ props.editor.off('blur', updateInstance);
109
+ document.removeEventListener('mousedown', hideMouseDown);
110
+ document.removeEventListener('keydown', hideKeyDown);
111
+ destroy();
112
+ });
113
+ </script>
@@ -0,0 +1,100 @@
1
+ <template>
2
+ <TextEditorPopover id="link-editor" v-model:visible="visibleModel" :editor="editor">
3
+ <div class="mds-grid">
4
+ <div class="mds-grid-row">
5
+ <span class="mds-grid-col mds-grid-fit-content">
6
+ <label class="mds-visually-hidden" for="link-url">{{ i18nText.visuallyHiddenLinkUrlLabel }}</label>
7
+ <input
8
+ id="link-url"
9
+ ref="linkInput"
10
+ v-model="linkUrlModel"
11
+ class="mds-form-control"
12
+ placeholder="example.com"
13
+ />
14
+ </span>
15
+ <span class="mds-grid-col">
16
+ <button class="mds-button mds-width-full" @click="setLink">{{ i18nText.addLink }}</button>
17
+ <button class="mds-button mds-button--plain mds-width-full" @click="removeLink">
18
+ {{ i18nText.removeLink }}
19
+ </button>
20
+ </span>
21
+ </div>
22
+ </div>
23
+ </TextEditorPopover>
24
+ </template>
25
+
26
+ <script setup>
27
+ import { computed, inject } from 'vue';
28
+ import TextEditorPopover from './TextEditorPopover.vue';
29
+ import { applyMissingProtocol } from './apply-missing-protocol';
30
+ import { nextTick } from 'process';
31
+
32
+ // eslint-disable-next-line no-undef
33
+ const props = defineProps({
34
+ visible: {
35
+ type: Boolean,
36
+ default: false,
37
+ },
38
+ linkUrl: {
39
+ type: String,
40
+ default: '',
41
+ },
42
+ editor: {
43
+ type: Object,
44
+ required: true,
45
+ },
46
+ });
47
+ // eslint-disable-next-line no-undef
48
+ const emit = defineEmits(['update:visible', 'update:linkUrl']);
49
+
50
+ const i18nText = inject('i18nText');
51
+
52
+ const visibleModel = computed({
53
+ get() {
54
+ return props.visible;
55
+ },
56
+ set(val) {
57
+ emit('update:visible', val);
58
+ },
59
+ });
60
+ const linkUrlModel = computed({
61
+ get() {
62
+ return props.linkUrl;
63
+ },
64
+ set(val) {
65
+ emit('update:linkUrl', val);
66
+ },
67
+ });
68
+
69
+ const setLink = () => {
70
+ // cancelled
71
+ if (linkUrlModel.value === null) {
72
+ visibleModel.value = false;
73
+ return;
74
+ }
75
+
76
+ // unset link if empty
77
+ if (linkUrlModel.value?.trim() === '') {
78
+ props.editor.chain().focus().extendMarkRange('link').unsetLink().run();
79
+ visibleModel.value = false;
80
+ return;
81
+ }
82
+ linkUrlModel.value = applyMissingProtocol(linkUrlModel.value);
83
+
84
+ // update link
85
+ nextTick(() => {
86
+ props.editor
87
+ .chain()
88
+ .focus()
89
+ .extendMarkRange('link')
90
+ .setLink({ href: linkUrlModel.value })
91
+ .setTextSelection(0)
92
+ .run();
93
+ visibleModel.value = false;
94
+ });
95
+ };
96
+ const removeLink = () => {
97
+ props.editor.chain().focus().extendMarkRange('link').unsetLink().run();
98
+ linkUrlModel.value = false;
99
+ };
100
+ </script>
@@ -1,16 +1,17 @@
1
1
  <template>
2
2
  <div class="mds-text-editor__menu" role="toolbar" :aria-label="i18nText.toolbarLabel" :aria-controls="id">
3
3
  <TextEditorButton
4
- ref="menuButton"
5
4
  v-for="button in menuButtons"
6
- :key="button.id"
7
5
  :id="button.id"
6
+ ref="menuButton"
7
+ :key="button.id"
8
8
  :label="button.label"
9
9
  :icon-name="button.iconName"
10
- :isActive="button.isActive?.(editor)"
10
+ :is-active="button.isActive?.(editor)"
11
11
  :disabled="button.isDisabled?.(editor)"
12
- :initialTabindex="firstFocusableButton.id === button.id ? 0 : -1"
12
+ :initial-tabindex="firstFocusableButton.id === button.id ? 0 : -1"
13
13
  :aria-pressed="button.id === 'undo' || button.id === 'redo' ? null : button.isActive?.(editor)"
14
+ :aria-expanded="button.ariaExpanded?.()"
14
15
  @click="button.onClick(editor)"
15
16
  @keyup.left="setFocusToSibling('previous', $event)"
16
17
  @keyup.up="setFocusToSibling('previous', $event)"
@@ -18,19 +19,24 @@
18
19
  @keyup.down="setFocusToSibling('next', $event)"
19
20
  @update-tab-index="updateTabIndex"
20
21
  />
22
+ <!-- <TextEditorPopoverLink v-if="editor" v-model:linkUrl="linkUrl" v-model:visible="showLinkEditor" :editor="editor" /> -->
21
23
  </div>
22
24
  </template>
23
25
 
24
26
  <script>
25
27
  import TextEditorButton from './TextEditorButton.vue';
28
+ // import TextEditorPopoverLink from './TextEditorPopoverLink.vue';
26
29
 
27
30
  export default {
28
31
  name: 'TextEditorToolbar',
29
32
 
30
33
  components: {
31
34
  TextEditorButton,
35
+ // TextEditorPopoverLink,
32
36
  },
33
37
 
38
+ inject: ['id', 'customMenuButtons', 'i18nText'],
39
+
34
40
  props: {
35
41
  editor: {
36
42
  type: Object,
@@ -38,8 +44,6 @@ export default {
38
44
  },
39
45
  },
40
46
 
41
- inject: ['id', 'customMenuButtons', 'i18nText'],
42
-
43
47
  data() {
44
48
  return {
45
49
  defaultMenuButtons: [
@@ -78,6 +82,25 @@ export default {
78
82
  onClick: (editor) => editor.commands.toggleOrderedList(),
79
83
  isActive: (editor) => editor.isActive('orderedList'),
80
84
  },
85
+ /* {
86
+ id: 'link',
87
+ label: 'Link',
88
+ iconName: 'text-link',
89
+ ariaExpanded: () => this.showLinkEditor,
90
+ onClick: (editor) => {
91
+ if (this.shouldShowLinkEditor()) {
92
+ // only show the bubble menu for links
93
+ this.showLinkEditor = true;
94
+ // update link in text input if we should show it
95
+ const previousUrl = editor.getAttributes('link').href;
96
+ this.linkUrl = previousUrl ?? '';
97
+ }
98
+ },
99
+ isActive: (editor) => editor.isActive('link'),
100
+ isDisabled: () => {
101
+ return !this.shouldShowLinkEditor();
102
+ },
103
+ }, */
81
104
  {
82
105
  id: 'undo',
83
106
  label: 'Undo',
@@ -93,9 +116,10 @@ export default {
93
116
  isDisabled: (editor) => !editor.can().redo(),
94
117
  },
95
118
  ],
119
+ // showLinkEditor: false,
120
+ // linkUrl: '',
96
121
  };
97
122
  },
98
-
99
123
  computed: {
100
124
  menuButtons() {
101
125
  if (this.customMenuButtons?.length) {
@@ -115,7 +139,6 @@ export default {
115
139
  return this.menuButtons.find((button) => !button.isDisabled?.(this.editor));
116
140
  },
117
141
  },
118
-
119
142
  methods: {
120
143
  findSiblings(currentElement, position) {
121
144
  let sibling = position === 'previous' ? currentElement.previousElementSibling : currentElement.nextElementSibling;
@@ -144,6 +167,12 @@ export default {
144
167
  }
145
168
  });
146
169
  },
170
+ /* shouldShowLinkEditor() {
171
+ // no selection, so cant open link editor
172
+ const hasSelection = this.editor.state.selection.$from.pos !== this.editor.state.selection.$to.pos;
173
+ const cursorIsAtLink = this.editor.isActive('link');
174
+ return hasSelection || cursorIsAtLink;
175
+ }, */
147
176
  },
148
177
  };
149
178
  </script>
@@ -0,0 +1,7 @@
1
+ const isValidProtocol = (href) => /^https?:\/\/|mailto:/.test(href);
2
+
3
+ export const applyMissingProtocol = (href) => {
4
+ const isValid = isValidProtocol(href);
5
+ if (!isValid) return `http://${href}`;
6
+ return href;
7
+ };
@@ -1 +1 @@
1
- import{_ as h,o as a,c as l,a as c,w as r,t as m,b as v,r as I,n as g,d as p,e as x,f as _,g as C,h as B,F as k,i as w,j as L}from"../plugin-vue_export-helper.js";const V={name:"ComboboxClear",inject:["iconPath","clearInput"]},S=["aria-label","title"],T={"aria-hidden":"true",focusable:"false",class:"mds-icon mds-icon--close mds-icon--sm"},M=["href"];function E(t,i,n,u,o,e){return a(),l("button",{class:"mds-combobox__clear mds-button mds-button--plain",type:"button",onClick:i[0]||(i[0]=d=>t.$emit("clear",d)),onKeydown:i[1]||(i[1]=r(d=>t.$emit("clear",d),["enter"])),"aria-label":e.clearInput,title:e.clearInput},[(a(),l("svg",T,[c("use",{href:`${e.iconPath}#icon-close`},null,8,M)]))],40,S)}var H=h(V,[["render",E]]);const K={name:"ListBox",props:{hidden:{type:Boolean,default:!0},isLoading:{type:Boolean,default:!0},comboboxid:{type:String,required:!0}},inject:["iconPath","loadingText"]},F=["aria-labelledby","hidden"],A={key:0,class:"mds-combobox-loading"},q={"aria-hidden":"true",focusable:"true",class:"mds-icon mds-icon--spinner mds-icon--after"},G=["href"],P={class:"mds-visually-hidden"};function j(t,i,n,u,o,e){return a(),l("ul",{class:"mds-combobox__listbox",role:"listbox","aria-labelledby":`${n.comboboxid}-label`,hidden:n.hidden},[n.isLoading?(a(),l("li",A,[(a(),l("svg",q,[c("use",{href:`${e.iconPath}#icon-spinner`},null,8,G)])),c("span",P,m(e.loadingText),1)])):v("",!0),I(t.$slots,"default")],8,F)}var N=h(K,[["render",j]]);const D={name:"ListBoxOption",props:{option:{type:Object,required:!0},focused:{type:Boolean,default:!1},searchValue:{type:String,default:""}},watch:{searchValue(t){return t},focused(t){t&&this.$refs.listItem.scrollIntoView(!1)}},methods:{highlightOption(){return this.option.label.replace(new RegExp(this.searchValue,"gi"),i=>`<span class="mds-combobox__option--marked">${i}</span>`)}}},R=["aria-selected","innerHTML"];function U(t,i,n,u,o,e){return a(),l("li",{ref:"listItem",class:g(["mds-combobox__option",{"mds-combobox__option--focused":n.focused}]),role:"option","aria-selected":n.focused.toString(),onMousedown:i[0]||(i[0]=d=>t.$emit("mousedown",d)),innerHTML:e.highlightOption()},null,42,R)}var $=h(D,[["render",U]]);const z={name:"Combobox",components:{ComboboxClear:H,ListBox:N,ListBoxOption:$},emits:["search","select-option","clear-all"],props:{comboboxid:{type:String,required:!0},placeholder:{type:String,default:""},name:{type:[String,Boolean],default:!1},value:{type:String,default:""},options:{type:Array,default:()=>[]},filterOptions:{type:Boolean,default:!0},iconpath:{type:String,default:"/assets/icons.svg"},dataAriaInvalid:{type:String,default:""},i18n:{type:String,default:""}},data(){return{expanded:!1,selected:null,chosen:null,searchValue:this.$props.value,resultCountMessage:null}},provide(){return{iconPath:this.iconpath,loadingText:this.i18nText.loadingText,clearInput:this.i18nText.clearInput}},mounted(){var n,u,o,e;const t=(u=(n=this.$el.parentElement)==null?void 0:n.parentElement)==null?void 0:u.querySelector(".mds-form-element__fallback input"),i=(e=(o=this.$el.parentElement)==null?void 0:o.parentElement)==null?void 0:e.querySelector(".mds-form-element__fallback select");t&&t.remove(),i&&i.removeAttribute("id")},computed:{inputValue(){return this.chosenOption?this.chosenOption.label:this.searchValue},selectedOption:{get(){return this.selected},set(t){this.selected=t}},chosenOption:{get(){return this.chosen},set(t){this.chosen=t,this.selectedOption=t,this.$emit("select-option",this.chosen)}},visibleOptions(){return this.filterOptions?this.options.filter(t=>t.label.toLowerCase().includes(this.searchValue.toLowerCase())):this.options},listBoxId(){return`${this.comboboxid}-listbox`},optionId(){return`${this.comboboxid}-option`},describedBy(){return`${this.comboboxid}-assistiveHint`},isLoading(){return this.options.length===0&&this.expanded},selectedOptionId(){const t=this.visibleOptions.indexOf(this.selectedOption);if(t>-1)return`${this.optionId}-${t}`},listBoxHidden(){return!this.expanded},lastOptionIndex(){return this.visibleOptions.length-1},ariaExpanded(){return this.expanded?"true":"false"},ariaInvalid(){return this.dataAriaInvalid?"true":"false"},i18nText(){return this.i18n?JSON.parse(this.i18n):{loadingText:"Loading",describedByText:"When autocomplete results are available, use up and down arrows to review and enter to select.",resultsMessage:"{count} result available",resultsMessage_plural:"{count} results available",clearInput:"clear input"}}},methods:{makeActive(){this.expanded=!0},makeInactive(){this.expanded=!1},handleInput(t){this.chosenOption=null,this.searchValue=t.target?t.target.value:"",this.handleChange(),this.$emit("search",this.searchValue),this.visibleOptions.length>0&&this.updateCount()},handleChange(){this.searchValue.length===0&&this.clearField(),this.searchValue.length>1?(this.makeActive(),this.updateCount()):this.makeInactive()},handleFocus(){this.handleChange(),this.visibleOptions.length>1&&this.updateCount()},handleClear(){this.clearField(),this.$refs.comboInput.focus()},clearField(){this.searchValue="",this.chosenOption=null,this.$emit("clear-all")},clickOption(t=this.selectedOption){this.chosenOption=t,this.makeInactive()},chooseOption(){this.chosenOption=this.selectedOption,this.makeInactive(),this.clearCount()},hiddenGuard(t){this.listBoxHidden||t.call(this)},onInputBlur(){this.makeInactive(),this.clearCount()},onKeyDown(){if(this.selectedOption){const t=this.visibleOptions.findIndex(n=>n.value===this.selectedOption.value),i=t===this.lastOptionIndex?t:t+1;this.selectedOption=this.visibleOptions[i]}else[this.selectedOption]=this.visibleOptions},onKeyUp(){if(this.selectedOption){const t=this.visibleOptions.findIndex(n=>n.value===this.selectedOption.value),i=t===0?t:t-1;this.selectedOption=this.visibleOptions[i]}else this.selectedOption=this.visibleOptions[this.lastOptionIndex]},onKeyHome(){[this.selectedOption]=this.visibleOptions},onKeyEnd(){this.selectedOption=this.visibleOptions[this.lastOptionIndex]},updateCount(){this.clearCount(),setTimeout(()=>{const t=this.visibleOptions.length===1?this.i18nText.resultsMessage:this.i18nText.resultsMessage_plural;this.resultCountMessage=t.replace("{count}",this.visibleOptions.length)},1400)},clearCount(){this.resultCountMessage=null}}},J=["value","id","name","placeholder","aria-owns","aria-expanded","aria-activedescendant","aria-invalid","aria-describedby"],W={"aria-live":"polite",role:"status",class:"mds-visually-hidden"},Q=["id"];function X(t,i,n,u,o,e){const d=p("ComboboxClear"),O=p("ListBoxOption"),y=p("ListBox");return a(),l("div",{class:g(["mds-combobox",{"mds-combobox--active":!e.listBoxHidden}]),onKeydown:[i[4]||(i[4]=r(s=>e.hiddenGuard(e.onKeyDown),["down"])),i[5]||(i[5]=r(s=>e.hiddenGuard(e.onKeyUp),["up"])),i[6]||(i[6]=r(s=>e.hiddenGuard(e.onKeyHome),["home"])),i[7]||(i[7]=r(s=>e.hiddenGuard(e.onKeyEnd),["end"])),i[8]||(i[8]=r((...s)=>e.makeInactive&&e.makeInactive(...s),["esc"])),i[9]||(i[9]=r(B((...s)=>e.chooseOption&&e.chooseOption(...s),["stop","prevent"]),["enter"]))]},[c("input",{onInput:i[0]||(i[0]=(...s)=>e.handleInput&&e.handleInput(...s)),value:e.inputValue,class:"mds-form-control",autocomplete:"off",type:"text",role:"combobox",ref:"comboInput",id:n.comboboxid,name:n.name,placeholder:n.placeholder,"aria-owns":e.listBoxId,"aria-expanded":e.ariaExpanded,"aria-autocomplete":"list","aria-activedescendant":e.selectedOptionId,"aria-invalid":e.ariaInvalid,"aria-describedby":e.describedBy,onChange:i[1]||(i[1]=(...s)=>e.handleChange&&e.handleChange(...s)),onBlur:i[2]||(i[2]=(...s)=>e.onInputBlur&&e.onInputBlur(...s)),onFocus:i[3]||(i[3]=(...s)=>e.handleFocus&&e.handleFocus(...s))},null,40,J),o.searchValue.length>0?(a(),x(d,{key:0,onClear:e.handleClear},null,8,["onClear"])):v("",!0),_(y,{id:e.listBoxId,hidden:e.listBoxHidden,isLoading:e.isLoading,comboboxid:n.comboboxid},{default:C(()=>[(a(!0),l(k,null,w(e.visibleOptions,(s,b)=>{var f;return a(),x(O,{key:b,option:s,id:`${e.optionId}-${b}`,focused:((f=e.selectedOption)==null?void 0:f.value)===(s==null?void 0:s.value),onMousedown:Z=>e.clickOption(s),searchValue:o.searchValue},null,8,["option","id","focused","onMousedown","searchValue"])}),128))]),_:1},8,["id","hidden","isLoading","comboboxid"]),c("div",W,m(o.resultCountMessage),1),c("span",{id:e.describedBy,style:{display:"none"}},m(e.i18nText.describedByText),9,Q)],34)}var Y=h(z,[["render",X]]);const te=L(Y,{shadowRoot:!1});export{te as default};
1
+ import{_ as h,o as a,c as l,a as c,w as r,t as m,b as v,r as I,n as g,d as p,e as x,f as _,g as C,F as B,h as w,i as k}from"../plugin-vue_export-helper.js";const L={name:"ComboboxClear",inject:["iconPath","clearInput"]},V=["aria-label","title"],S={"aria-hidden":"true",focusable:"false",class:"mds-icon mds-icon--close mds-icon--sm"},T=["href"];function E(t,n,s,u,o,e){return a(),l("button",{class:"mds-combobox__clear mds-button mds-button--plain",type:"button",onClick:n[0]||(n[0]=d=>t.$emit("clear",d)),onKeydown:n[1]||(n[1]=r(d=>t.$emit("clear",d),["enter"])),"aria-label":e.clearInput,title:e.clearInput},[(a(),l("svg",S,[c("use",{href:`${e.iconPath}#icon-close`},null,8,T)]))],40,V)}var K=h(L,[["render",E]]);const M={name:"ListBox",props:{hidden:{type:Boolean,default:!0},isLoading:{type:Boolean,default:!0},comboboxid:{type:String,required:!0}},inject:["iconPath","loadingText"]},H=["aria-labelledby","hidden"],F={key:0,class:"mds-combobox-loading"},D={"aria-hidden":"true",focusable:"true",class:"mds-icon mds-icon--spinner mds-icon--after"},A=["href"],q={class:"mds-visually-hidden"};function G(t,n,s,u,o,e){return a(),l("ul",{class:"mds-combobox__listbox",role:"listbox","aria-labelledby":`${s.comboboxid}-label`,hidden:s.hidden},[s.isLoading?(a(),l("li",F,[(a(),l("svg",D,[c("use",{href:`${e.iconPath}#icon-spinner`},null,8,A)])),c("span",q,m(e.loadingText),1)])):v("",!0),I(t.$slots,"default")],8,H)}var P=h(M,[["render",G]]);const N={name:"ListBoxOption",props:{option:{type:Object,required:!0},focused:{type:Boolean,default:!1},searchValue:{type:String,default:""}},watch:{searchValue(t){return t},focused(t){t&&this.$refs.listItem.scrollIntoView(!1)}},methods:{highlightOption(){return this.option.label.replace(new RegExp(this.searchValue,"gi"),n=>`<span class="mds-combobox__option--marked">${n}</span>`)}}},j=["aria-selected","innerHTML"];function R(t,n,s,u,o,e){return a(),l("li",{ref:"listItem",class:g(["mds-combobox__option",{"mds-combobox__option--focused":s.focused}]),role:"option","aria-selected":s.focused.toString(),onMousedown:n[0]||(n[0]=d=>t.$emit("mousedown",d)),innerHTML:e.highlightOption()},null,42,j)}var U=h(N,[["render",R]]);const $={name:"Combobox",components:{ComboboxClear:K,ListBox:P,ListBoxOption:U},emits:["search","select-option","clear-all"],props:{comboboxid:{type:String,required:!0},placeholder:{type:String,default:""},name:{type:[String,Boolean],default:!1},value:{type:String,default:""},options:{type:Array,default:()=>[]},filterOptions:{type:Boolean,default:!0},iconpath:{type:String,default:"/assets/icons.svg"},dataAriaInvalid:{type:String,default:""},i18n:{type:String,default:""}},data(){return{expanded:!1,selected:null,chosen:null,searchValue:this.$props.value,resultCountMessage:null}},provide(){return{iconPath:this.iconpath,loadingText:this.i18nText.loadingText,clearInput:this.i18nText.clearInput}},mounted(){var s,u,o,e;const t=(u=(s=this.$el.parentElement)==null?void 0:s.parentElement)==null?void 0:u.querySelector(".mds-form-element__fallback input"),n=(e=(o=this.$el.parentElement)==null?void 0:o.parentElement)==null?void 0:e.querySelector(".mds-form-element__fallback select");t&&t.remove(),n&&n.removeAttribute("id")},computed:{inputValue(){return this.chosenOption?this.chosenOption.label:this.searchValue},selectedOption:{get(){return this.selected},set(t){this.selected=t}},chosenOption:{get(){return this.chosen},set(t){this.chosen=t,this.selectedOption=t,this.$emit("select-option",this.chosen)}},visibleOptions(){return this.filterOptions?this.options.filter(t=>t.label.toLowerCase().includes(this.searchValue.toLowerCase())):this.options},listBoxId(){return`${this.comboboxid}-listbox`},optionId(){return`${this.comboboxid}-option`},describedBy(){return`${this.comboboxid}-assistiveHint`},isLoading(){return this.options.length===0&&this.expanded},selectedOptionId(){const t=this.visibleOptions.indexOf(this.selectedOption);if(t>-1)return`${this.optionId}-${t}`},listBoxHidden(){return!this.expanded},lastOptionIndex(){return this.visibleOptions.length-1},ariaExpanded(){return this.expanded?"true":"false"},ariaInvalid(){return this.dataAriaInvalid?"true":"false"},i18nText(){return this.i18n?JSON.parse(this.i18n):{loadingText:"Loading",describedByText:"When autocomplete results are available, use up and down arrows to review and enter to select.",resultsMessage:"{count} result available",resultsMessage_plural:"{count} results available",clearInput:"clear input"}}},methods:{makeActive(){this.expanded=!0},makeInactive(){this.expanded=!1},handleInput(t){this.chosenOption=null,this.searchValue=t.target?t.target.value:"",this.handleChange(),this.$emit("search",this.searchValue),this.visibleOptions.length>0&&this.updateCount()},handleChange(){this.searchValue.length===0&&this.clearField(),this.searchValue.length>1?(this.makeActive(),this.updateCount()):this.makeInactive()},handleFocus(){this.handleChange(),this.visibleOptions.length>1&&this.updateCount()},handleClear(){this.clearField(),this.$refs.comboInput.focus()},clearField(){this.searchValue="",this.chosenOption=null,this.$emit("clear-all")},clickOption(t=this.selectedOption){this.chosenOption=t,this.makeInactive()},handleKeyDownEnter(t){this.expanded&&(t.preventDefault(),this.chooseOption())},chooseOption(){this.chosenOption=this.selectedOption,this.makeInactive(),this.clearCount()},hiddenGuard(t){this.listBoxHidden||t.call(this)},onInputBlur(){this.makeInactive(),this.clearCount()},onKeyDown(){if(this.selectedOption){const t=this.visibleOptions.findIndex(s=>s.value===this.selectedOption.value),n=t===this.lastOptionIndex?t:t+1;this.selectedOption=this.visibleOptions[n]}else[this.selectedOption]=this.visibleOptions},onKeyUp(){if(this.selectedOption){const t=this.visibleOptions.findIndex(s=>s.value===this.selectedOption.value),n=t===0?t:t-1;this.selectedOption=this.visibleOptions[n]}else this.selectedOption=this.visibleOptions[this.lastOptionIndex]},onKeyHome(){[this.selectedOption]=this.visibleOptions},onKeyEnd(){this.selectedOption=this.visibleOptions[this.lastOptionIndex]},updateCount(){this.clearCount(),setTimeout(()=>{const t=this.visibleOptions.length===1?this.i18nText.resultsMessage:this.i18nText.resultsMessage_plural;this.resultCountMessage=t.replace("{count}",this.visibleOptions.length)},1400)},clearCount(){this.resultCountMessage=null}}},z=["value","id","name","placeholder","aria-owns","aria-expanded","aria-activedescendant","aria-invalid","aria-describedby"],J={"aria-live":"polite",role:"status",class:"mds-visually-hidden"},W=["id"];function Q(t,n,s,u,o,e){const d=p("ComboboxClear"),O=p("ListBoxOption"),y=p("ListBox");return a(),l("div",{class:g(["mds-combobox",{"mds-combobox--active":!e.listBoxHidden}]),onKeydown:[n[4]||(n[4]=r(i=>e.hiddenGuard(e.onKeyDown),["down"])),n[5]||(n[5]=r(i=>e.hiddenGuard(e.onKeyUp),["up"])),n[6]||(n[6]=r(i=>e.hiddenGuard(e.onKeyHome),["home"])),n[7]||(n[7]=r(i=>e.hiddenGuard(e.onKeyEnd),["end"])),n[8]||(n[8]=r((...i)=>e.makeInactive&&e.makeInactive(...i),["esc"])),n[9]||(n[9]=r((...i)=>e.handleKeyDownEnter&&e.handleKeyDownEnter(...i),["enter"]))]},[c("input",{onInput:n[0]||(n[0]=(...i)=>e.handleInput&&e.handleInput(...i)),value:e.inputValue,class:"mds-form-control",autocomplete:"off",type:"text",role:"combobox",ref:"comboInput",id:s.comboboxid,name:s.name,placeholder:s.placeholder,"aria-owns":e.listBoxId,"aria-expanded":e.ariaExpanded,"aria-autocomplete":"list","aria-activedescendant":e.selectedOptionId,"aria-invalid":e.ariaInvalid,"aria-describedby":e.describedBy,onChange:n[1]||(n[1]=(...i)=>e.handleChange&&e.handleChange(...i)),onBlur:n[2]||(n[2]=(...i)=>e.onInputBlur&&e.onInputBlur(...i)),onFocus:n[3]||(n[3]=(...i)=>e.handleFocus&&e.handleFocus(...i))},null,40,z),o.searchValue.length>0?(a(),x(d,{key:0,onClear:e.handleClear},null,8,["onClear"])):v("",!0),_(y,{id:e.listBoxId,hidden:e.listBoxHidden,isLoading:e.isLoading,comboboxid:s.comboboxid},{default:C(()=>[(a(!0),l(B,null,w(e.visibleOptions,(i,b)=>{var f;return a(),x(O,{key:b,option:i,id:`${e.optionId}-${b}`,focused:((f=e.selectedOption)==null?void 0:f.value)===(i==null?void 0:i.value),onMousedown:Y=>e.clickOption(i),searchValue:o.searchValue},null,8,["option","id","focused","onMousedown","searchValue"])}),128))]),_:1},8,["id","hidden","isLoading","comboboxid"]),c("div",J,m(o.resultCountMessage),1),c("span",{id:e.describedBy,style:{display:"none"}},m(e.i18nText.describedByText),9,W)],34)}var X=h($,[["render",Q]]);const ee=k(X,{shadowRoot:!1});export{ee as default};