goodteditor-ui 1.0.10 → 1.0.11

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/index.js CHANGED
@@ -16,6 +16,7 @@ import Pagination from './src/components/ui/Pagination.vue';
16
16
  import Paginator from './src/components/ui/Paginator.vue';
17
17
  import Popover from './src/components/ui/Popover.vue';
18
18
  import Popup from './src/components/ui/Popup.vue';
19
+ import ResponsiveContainer from './src/components/ui/ResponsiveContainer.vue';
19
20
  import Select from './src/components/ui/Select.vue';
20
21
  import TimePicker from './src/components/ui/TimePicker.vue';
21
22
  import Tooltip from './src/components/ui/Tooltip.vue';
@@ -40,8 +41,9 @@ export {
40
41
  Paginator,
41
42
  Popover,
42
43
  Popup,
44
+ ResponsiveContainer,
43
45
  Select,
44
46
  TimePicker,
45
47
  Tooltip,
46
- Grid
48
+ Grid,
47
49
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "goodteditor-ui",
3
- "version": "1.0.10",
3
+ "version": "1.0.11",
4
4
  "main": "index.js",
5
5
  "homepage": "https://goodt-ui.netlify.app/",
6
6
  "scripts": {
@@ -0,0 +1,58 @@
1
+ ```vue
2
+ <template>
3
+ <div class="pad-l5">
4
+ <div class="p">
5
+ <div class="form-label form-label-small">Tile width:</div>
6
+ <input class="input input-small" type="number" min="0" step="10" v-model.number="tileWidth">
7
+ </div>
8
+
9
+ <ui-responsive-container v-bind="binds" v-slot="{ breakpoint, width, height }">
10
+ <!-- {demo-tile} -->
11
+ <div class="tile" :class="[`tile--${breakpoint}`]" :style="tileStyle">
12
+ <div class="tile-body">
13
+ <div class="row">
14
+ <div class="col col-auto tile__avatar">
15
+ <img class="avatar avatar-4 round" src="https://picsum.photos/150/150" >
16
+ </div>
17
+ <div class="col">
18
+ <div class="text-bold">John Wick</div>
19
+ <div class="text-xsmall">john.wick@site.com</div>
20
+ <code>{{breakpoint}}</code> | <code>{{width}}&times;{{height}}</code>
21
+ </div>
22
+ </div>
23
+ </div>
24
+ <!-- {/demo-tile} -->
25
+ </div>
26
+ </ui-responsive-container>
27
+ </div>
28
+ </template>
29
+ <script>
30
+ import UiResponsiveContainer from './ResponsiveContainer.vue';
31
+
32
+ export default {
33
+ components: { UiResponsiveContainer },
34
+ data: () => ({
35
+ binds: {
36
+ breakpoints: {
37
+ 's': 450,
38
+ 'm': 550,
39
+ 'l': 650,
40
+ }
41
+ },
42
+ tileWidth: ''
43
+ }),
44
+ computed: {
45
+ tileStyle() {
46
+ return { width: `${this.tileWidth}px` }
47
+ }
48
+ }
49
+ };
50
+ </script>
51
+ <style scoped>
52
+ .tile { min-width: 150px; }
53
+ .tile--s { color: red; }
54
+ .tile--s .tile__avatar { display:none; }
55
+ .tile--m { color: orange; }
56
+ .tile--l { color: green; }
57
+ </style>
58
+ ```
@@ -0,0 +1,99 @@
1
+ <script>
2
+ import { debounce } from './utils/Helpers';
3
+
4
+ const ObserverManager = {
5
+ observer: null,
6
+ records: new Map(),
7
+ register({ fn, el }) {
8
+ const { records } = this;
9
+ if (!records.size) {
10
+ this.createObserver();
11
+ }
12
+ records.set(el, fn);
13
+ this.observer.observe(el);
14
+ },
15
+ unregister(el) {
16
+ const { records } = this;
17
+ records.delete(el);
18
+ this.observer.unobserve(el);
19
+ if (!records.size) {
20
+ this.destroyObserver();
21
+ }
22
+ },
23
+ createObserver() {
24
+ const { records } = this;
25
+ const callback = entries => {
26
+ entries.forEach(entry => {
27
+ const fn = records.get(entry.target);
28
+ fn && fn(entry);
29
+ });
30
+ };
31
+ this.observer = new ResizeObserver(debounce(callback, 50));
32
+ },
33
+ destroyObserver() {
34
+ this.observer.disconnect();
35
+ this.observer = null;
36
+ },
37
+ };
38
+
39
+ export default {
40
+ props: {
41
+ /**
42
+ * Breakpoints hash { '<name>': '<max-width-in-px>' }<br>
43
+ * example:
44
+ * <pre>{ 'mobile': 400, 'tablet': 800 }</pre>
45
+ */
46
+ breakpoints: {
47
+ type: Object,
48
+ default: () => ({}),
49
+ },
50
+ },
51
+ data: () => ({ width: 0, height: 0 }),
52
+ computed: {
53
+ /**
54
+ * @return {[string, number][]}
55
+ */
56
+ breakpointEntries() {
57
+ return Object.entries(this.breakpoints).sort(([, aVal], [, bVal]) => aVal - bVal);
58
+ },
59
+ /**
60
+ * @return {string}
61
+ */
62
+ breakpoint() {
63
+ const { breakpointEntries, width } = this;
64
+ if (width === 0) {
65
+ return null;
66
+ }
67
+ const match = breakpointEntries.find(([, value]) => width < value);
68
+ return match?.[0] ?? null;
69
+ },
70
+ },
71
+ mounted() {
72
+ const { $el: el } = this;
73
+ const fn = ({ contentRect }) => {
74
+ this.width = contentRect.width | 0;
75
+ this.height = contentRect.height | 0;
76
+ };
77
+ ObserverManager.register({ fn, el });
78
+ },
79
+ beforeDestroy() {
80
+ ObserverManager.unregister(this.$el);
81
+ },
82
+ render(h) {
83
+ const { breakpoint, width, height } = this;
84
+ /*
85
+ @slot Page data slot
86
+ @binding {string} breakpoint breakpoint name
87
+ @binding {number} width current container width (px)
88
+ @binding {number} height current container height (px)
89
+ */
90
+ const content = this.$scopedSlots.default
91
+ ? this.$scopedSlots.default({ breakpoint, width, height })
92
+ : null;
93
+ if (content.length > 1) {
94
+ return h('div', 'Slot content should have one child');
95
+ }
96
+ return content;
97
+ },
98
+ };
99
+ </script>