@dejwcake/craftable 2.1.1 → 2.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dejwcake/craftable",
3
- "version": "2.1.1",
3
+ "version": "2.2.0",
4
4
  "description": "This is a frontend dependency for Craftable. Craftable is a Laravel-based open-source toolkit for building administration interfaces.",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <a class="btn btn-sm btn-outline-secondary" :href="url">
3
+ <i class="fa fa-arrow-left"></i> {{ translations.back }}
4
+ </a>
5
+ </template>
6
+
7
+ <script setup>
8
+ defineProps({
9
+ url: { type: String, required: true },
10
+ translations: {
11
+ type: Object,
12
+ default: () => ({
13
+ back: 'Back',
14
+ }),
15
+ },
16
+ });
17
+ </script>
@@ -0,0 +1,17 @@
1
+ <template>
2
+ <a class="btn btn-sm btn-spinner btn-info" :href="url" :title="translations.show_btn" role="button">
3
+ <i class="fa fa-eye"></i>
4
+ </a>
5
+ </template>
6
+
7
+ <script setup>
8
+ defineProps({
9
+ url: { type: String, required: true },
10
+ translations: {
11
+ type: Object,
12
+ default: () => ({
13
+ show_btn: 'Show',
14
+ }),
15
+ },
16
+ });
17
+ </script>
@@ -1,5 +1,22 @@
1
1
  import { ref, watch, onBeforeUnmount } from 'vue';
2
2
 
3
+ /**
4
+ * Container width in pixels mapped to the highest column priority still shown at that width.
5
+ *
6
+ * | container width | highest priority shown |
7
+ * |-----------------|------------------------|
8
+ * | 1800 and up | 10 |
9
+ * | 1600 - 1799 | 8 |
10
+ * | 1400 - 1599 | 6 |
11
+ * | 1200 - 1399 | 4 |
12
+ * | 1000 - 1199 | 3 |
13
+ * | 800 - 999 | 2 |
14
+ * | below 800 | 0 |
15
+ *
16
+ * The width measured is the container's `contentRect`, so padding is already excluded: a card in a
17
+ * 1512px window measures around 1190px and lands on the `1000 - 1199` row, where only priorities
18
+ * 0 to 3 are shown.
19
+ */
3
20
  const defaultBreakpoints = [
4
21
  { minWidth: 1800, maxPriority: 10 },
5
22
  { minWidth: 1600, maxPriority: 8 },
@@ -10,6 +27,23 @@ const defaultBreakpoints = [
10
27
  { minWidth: 0, maxPriority: 0 },
11
28
  ];
12
29
 
30
+ /**
31
+ * Hides lower-importance columns as a listing's container narrows.
32
+ *
33
+ * Each column is given a **priority**, not a position: a lower number survives a narrower
34
+ * container, and columns sharing a number appear and disappear together. Numbering columns
35
+ * `0, 1, 2, …` in the order they are written therefore ties importance to layout by accident — the
36
+ * fifth column onwards is hidden on an ordinary laptop, because a priority above 3 needs a
37
+ * container wider than 1200px. Assign the numbers deliberately instead.
38
+ *
39
+ * @param {import('vue').Ref<HTMLElement|null>} containerRef element whose width drives the choice.
40
+ * @param {{ breakpoints?: Array<{ minWidth: number, maxPriority: number }> }} [options]
41
+ * `breakpoints` replaces the defaults above; order them widest first.
42
+ * @returns {{
43
+ * isColumnWithinPriority: (priority: number) => boolean,
44
+ * isColumnVisible: (priority: number) => boolean,
45
+ * }}
46
+ */
13
47
  export function useResponsiveColumns(containerRef, options = {}) {
14
48
  const breakpoints = options.breakpoints || defaultBreakpoints;
15
49
  const currentMaxPriority = ref(10);
@@ -54,9 +88,23 @@ export function useResponsiveColumns(containerRef, options = {}) {
54
88
  }
55
89
  });
56
90
 
57
- function isColumnVisible(priority) {
91
+ /**
92
+ * Whether a column of this priority is shown at the container's current width.
93
+ *
94
+ * @param {number} priority lower survives a narrower container; see the breakpoint table.
95
+ * @returns {boolean}
96
+ */
97
+ function isColumnWithinPriority(priority) {
58
98
  return priority <= currentMaxPriority.value;
59
99
  }
60
100
 
61
- return { isColumnVisible };
101
+ return {
102
+ isColumnWithinPriority,
103
+ /**
104
+ * The original name for `isColumnWithinPriority`, and still fully supported -- every
105
+ * existing listing calls it, and the generator emits it. It reads like a column index,
106
+ * which the argument is not.
107
+ */
108
+ isColumnVisible: isColumnWithinPriority,
109
+ };
62
110
  }
package/src/index.js CHANGED
@@ -22,8 +22,10 @@ export { default as BulkCheckboxRow } from './components/listing/BulkCheckboxRow
22
22
  export { default as BulkOperationsBar } from './components/listing/BulkOperationsBar.vue';
23
23
  export { default as PublishedAtColumn } from './components/listing/PublishedAtColumn.vue';
24
24
  export { default as ListingHeader } from './components/listing/ListingHeader.vue';
25
+ export { default as ShowButton } from './components/listing/ShowButton.vue';
25
26
  export { default as EditButton } from './components/listing/EditButton.vue';
26
27
  export { default as DeleteButton } from './components/listing/DeleteButton.vue';
28
+ export { default as BackButton } from './components/BackButton.vue';
27
29
  export { default as ConfirmModal } from './components/ConfirmModal.vue';
28
30
  export { default as ToggleSwitch } from './components/listing/ToggleSwitch.vue';
29
31
  export { default as ReadOnlySwitch } from './components/ReadOnlySwitch.vue';