vue-devui 1.0.0-beta.8 → 1.0.0-beta.9

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.
@@ -14,8 +14,12 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { defineComponent, createVNode, ref, computed, withDirectives, Transition, renderSlot, vShow, resolveDirective } from "vue";
17
+ import { defineComponent, inject, withDirectives, createVNode, vShow, ref, reactive, computed, provide, toRefs, Fragment, resolveComponent, resolveDirective, Transition, renderSlot } from "vue";
18
18
  const editableSelectProps = {
19
+ appendToBody: {
20
+ type: Boolean,
21
+ default: false
22
+ },
19
23
  modelValue: {
20
24
  type: [String, Number]
21
25
  },
@@ -24,7 +28,8 @@ const editableSelectProps = {
24
28
  default: () => []
25
29
  },
26
30
  width: {
27
- type: Number
31
+ type: Number,
32
+ default: 450
28
33
  },
29
34
  maxHeight: {
30
35
  type: Number
@@ -55,57 +60,77 @@ const editableSelectProps = {
55
60
  },
56
61
  searchFn: {
57
62
  type: Function
63
+ },
64
+ loadMore: {
65
+ type: Function
58
66
  }
59
67
  };
60
- var editableSelect = "";
61
- var Icon = defineComponent({
62
- name: "DIcon",
63
- props: {
64
- name: {
65
- type: String,
66
- required: true
67
- },
68
- size: {
69
- type: String,
70
- default: "inherit"
71
- },
72
- color: {
73
- type: String,
74
- default: "inherit"
75
- },
76
- classPrefix: {
77
- type: String,
78
- default: "icon"
79
- }
80
- },
68
+ const selectDropdownProps = {
69
+ options: {
70
+ type: Array,
71
+ default: () => []
72
+ }
73
+ };
74
+ function className(classStr, classOpt) {
75
+ let classname = classStr;
76
+ if (typeof classOpt === "object") {
77
+ Object.keys(classOpt).forEach((key) => {
78
+ classOpt[key] && (classname += ` ${key}`);
79
+ });
80
+ }
81
+ return classname;
82
+ }
83
+ var SelectDropdown = defineComponent({
84
+ name: "DSelectDropdown",
85
+ props: selectDropdownProps,
81
86
  setup(props) {
82
- return __spreadValues({}, props);
83
- },
84
- render() {
87
+ const select = inject("InjectionKey");
85
88
  const {
86
- name,
87
- size,
88
- color,
89
- classPrefix
90
- } = this;
91
- return /^((https?):)?\/\//.test(name) ? createVNode("img", {
92
- "src": name,
93
- "alt": name.split("/")[name.split("/").length - 1],
94
- "style": {
95
- width: size
96
- }
97
- }, null) : createVNode("i", {
98
- "class": `${classPrefix} ${classPrefix}-${name}`,
99
- "style": {
100
- fontSize: size,
101
- color
102
- }
103
- }, null);
89
+ props: selectProps,
90
+ dropdownRef,
91
+ visible,
92
+ selectOptionClick,
93
+ renderDefaultSlots,
94
+ renderEmptySlots,
95
+ selectedIndex,
96
+ loadMore
97
+ } = select;
98
+ const {
99
+ maxHeight
100
+ } = selectProps;
101
+ return () => {
102
+ const getLiCls = (item, index2) => {
103
+ const {
104
+ disabledKey
105
+ } = selectProps;
106
+ return className("devui-dropdown-item", {
107
+ disabled: disabledKey ? !!item[disabledKey] : false,
108
+ selected: selectedIndex.value === index2
109
+ });
110
+ };
111
+ return withDirectives(createVNode("div", {
112
+ "class": "devui-dropdown-menu"
113
+ }, [createVNode("ul", {
114
+ "ref": dropdownRef,
115
+ "class": "devui-list-unstyled scroll-height",
116
+ "style": {
117
+ maxHeight: maxHeight + "px"
118
+ },
119
+ "onScroll": loadMore
120
+ }, [props.options.map((o, index2) => {
121
+ return createVNode("li", {
122
+ "class": getLiCls(o, index2),
123
+ "onClick": ($evnet) => selectOptionClick($evnet, o)
124
+ }, [renderDefaultSlots(o)]);
125
+ }), withDirectives(createVNode("li", {
126
+ "class": "devui-no-result-template"
127
+ }, [createVNode("div", {
128
+ "class": "devui-no-data-tip"
129
+ }, [renderEmptySlots()])]), [[vShow, props.options.length === 0]])])]), [[vShow, visible]]);
130
+ };
104
131
  }
105
132
  });
106
- Icon.install = function(app) {
107
- app.component(Icon.name, Icon);
108
- };
133
+ var editableSelect = "";
109
134
  const inBrowser = typeof window !== "undefined";
110
135
  function on(element, eventName, handler) {
111
136
  if (document.addEventListener) {
@@ -161,15 +186,6 @@ const clickoutsideDirective = {
161
186
  delete el[ctx];
162
187
  }
163
188
  };
164
- function className(classStr, classOpt) {
165
- let classname = classStr;
166
- if (typeof classOpt === "object") {
167
- Object.keys(classOpt).forEach((key) => {
168
- classOpt[key] && (classname += ` ${key}`);
169
- });
170
- }
171
- return classname;
172
- }
173
189
  var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
174
190
  var lodash = { exports: {} };
175
191
  /**
@@ -5590,11 +5606,54 @@ var EditableSelect = defineComponent({
5590
5606
  props: editableSelectProps,
5591
5607
  emits: ["update:modelValue"],
5592
5608
  setup(props, ctx2) {
5593
- const dropdownRef = ref(null);
5609
+ const renderDropdown = (condition, type) => {
5610
+ if (!condition && type === 0) {
5611
+ return createVNode(Transition, {
5612
+ "name": "fade"
5613
+ }, {
5614
+ default: () => [createVNode(SelectDropdown, {
5615
+ "options": filteredOptions.value
5616
+ }, null)]
5617
+ });
5618
+ } else if (condition && type === 1) {
5619
+ return createVNode(resolveComponent("d-flexible-overlay"), {
5620
+ "hasBackdrop": false,
5621
+ "origin": origin,
5622
+ "position": position,
5623
+ "visible": visible.value,
5624
+ "onUpdate:visible": ($event) => visible.value = $event
5625
+ }, {
5626
+ default: () => [createVNode("div", {
5627
+ "class": "devui-dropdown",
5628
+ "style": {
5629
+ width: props.width + "px"
5630
+ }
5631
+ }, [createVNode(SelectDropdown, {
5632
+ "options": filteredOptions.value
5633
+ }, null)])]
5634
+ });
5635
+ }
5636
+ };
5637
+ const renderDefaultSlots = (item) => {
5638
+ return ctx2.slots.default ? renderSlot(ctx2.slots, "default", {
5639
+ item
5640
+ }) : item.name;
5641
+ };
5642
+ const renderEmptySlots = () => {
5643
+ return ctx2.slots.empty ? renderSlot(ctx2.slots, "empty") : emptyText.value;
5644
+ };
5645
+ const origin = ref();
5646
+ const dropdownRef = ref();
5594
5647
  const visible = ref(false);
5595
5648
  const inputValue = ref("");
5596
- const activeIndex = ref(0);
5649
+ const selectedIndex = ref(0);
5597
5650
  const query = ref(props.modelValue);
5651
+ const position = reactive({
5652
+ originX: "left",
5653
+ originY: "bottom",
5654
+ overlayX: "left",
5655
+ overlayY: "top"
5656
+ });
5598
5657
  const wait = computed(() => props.remote ? 300 : 0);
5599
5658
  const emptyText = computed(() => {
5600
5659
  const options = filteredOptions.value;
@@ -5670,7 +5729,7 @@ var EditableSelect = defineComponent({
5670
5729
  e.stopPropagation();
5671
5730
  } else {
5672
5731
  query.value = item.name;
5673
- activeIndex.value = findIndex(item);
5732
+ selectedIndex.value = findIndex(item);
5674
5733
  inputValue.value = "";
5675
5734
  ctx2.emit("update:modelValue", item.name);
5676
5735
  }
@@ -5680,28 +5739,31 @@ var EditableSelect = defineComponent({
5680
5739
  return;
5681
5740
  const dropdownVal = dropdownRef.value;
5682
5741
  if (dropdownVal.clientHeight + dropdownVal.scrollTop >= dropdownVal.scrollHeight) {
5683
- props.remoteMethod(inputValue.value);
5742
+ props.loadMore();
5684
5743
  }
5685
5744
  };
5745
+ provide("InjectionKey", {
5746
+ dropdownRef,
5747
+ props: reactive(__spreadValues({}, toRefs(props))),
5748
+ visible,
5749
+ emptyText,
5750
+ selectedIndex,
5751
+ loadMore,
5752
+ selectOptionClick,
5753
+ renderDefaultSlots,
5754
+ renderEmptySlots
5755
+ });
5686
5756
  return () => {
5687
- const selectCls = className("devui-form-group devui-has-feedback", {
5757
+ const selectCls = className("devui-editable-select devui-form-group devui-has-feedback", {
5688
5758
  "devui-select-open": visible.value
5689
5759
  });
5690
5760
  const inputCls = className("devui-form-control devui-dropdown-origin devui-dropdown-origin-open", {
5691
5761
  disabled: props.disabled
5692
5762
  });
5693
- const getLiCls = (item, index2) => {
5694
- const {
5695
- disabledKey
5696
- } = props;
5697
- return className("devui-dropdown-item", {
5698
- disabled: disabledKey ? !!item[disabledKey] : false,
5699
- selected: activeIndex.value === index2
5700
- });
5701
- };
5702
- return withDirectives(createVNode("div", {
5763
+ return createVNode(Fragment, null, [withDirectives(createVNode("div", {
5703
5764
  "class": selectCls,
5704
- "onClick": toggleMenu
5765
+ "onClick": toggleMenu,
5766
+ "ref": origin
5705
5767
  }, [createVNode("input", {
5706
5768
  "class": inputCls,
5707
5769
  "type": "text",
@@ -5711,36 +5773,9 @@ var EditableSelect = defineComponent({
5711
5773
  "class": "devui-form-control-feedback"
5712
5774
  }, [createVNode("span", {
5713
5775
  "class": "devui-select-chevron-icon"
5714
- }, [createVNode(Icon, {
5776
+ }, [createVNode(resolveComponent("d-icon"), {
5715
5777
  "name": "select-arrow"
5716
- }, null)])]), createVNode("div", {
5717
- "class": "devui-editable-select"
5718
- }, [createVNode(Transition, {
5719
- "name": "fade"
5720
- }, {
5721
- default: () => [withDirectives(createVNode("div", {
5722
- "class": "devui-dropdown-menu"
5723
- }, [createVNode("ul", {
5724
- "class": "devui-list-unstyled scroll-height",
5725
- "ref": dropdownRef,
5726
- "style": {
5727
- maxHeight: props.maxHeight + "px"
5728
- },
5729
- "onScroll": loadMore
5730
- }, [filteredOptions.value.map((item, index2) => {
5731
- return createVNode("li", {
5732
- "class": getLiCls(item, index2),
5733
- "onClick": ($evnet) => selectOptionClick($evnet, item),
5734
- "key": item.name
5735
- }, [ctx2.slots.default ? renderSlot(ctx2.slots, "default", {
5736
- item
5737
- }) : item.name]);
5738
- }), withDirectives(createVNode("li", {
5739
- "class": "devui-no-result-template"
5740
- }, [createVNode("div", {
5741
- "class": "devui-no-data-tip"
5742
- }, [emptyText.value])]), [[vShow, filteredOptions.value.length === 0]])])]), [[vShow, visible.value]])]
5743
- })])]), [[resolveDirective("click-outside"), handleClose]]);
5778
+ }, null)])]), renderDropdown(props.appendToBody, 0)]), [[resolveDirective("click-outside"), handleClose]]), renderDropdown(props.appendToBody, 1)]);
5744
5779
  };
5745
5780
  }
5746
5781
  });