ywana-core8 0.1.11 → 0.1.13

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": "ywana-core8",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "ywana-core8",
5
5
  "homepage": "https://ywana.github.io/workspace",
6
6
  "author": "Ernesto Roldan Garcia",
@@ -27,6 +27,7 @@ export const TablePage2 = (props) => {
27
27
  groupBy, validator,
28
28
  formFilter, tableFilter, editorFilter = false,
29
29
  tabbedBy,
30
+ sortedBy,
30
31
  tableClassName,
31
32
  children,
32
33
  onSelect,
@@ -139,7 +140,7 @@ export const TablePage2 = (props) => {
139
140
  </menu>
140
141
  ) : null}
141
142
  <main key={id} className={`table-page ${className}`}>
142
- <TableEditor icon={icon} title={name} schema={schema} delay={delay} editable={editable} tabbedBy={tabbedBy} groupBy={groupBy} filter={tableFilter} actions={tableActions} canDelete={canDelete} className={tableClassName} />
143
+ <TableEditor icon={icon} title={name} schema={schema} delay={delay} editable={editable} tabbedBy={tabbedBy} groupBy={groupBy} sortedBy={sortedBy} filter={tableFilter} actions={tableActions} canDelete={canDelete} className={tableClassName} />
143
144
  {children ? <article>{children}</article> : null}
144
145
  </main>
145
146
  {renderAside()}
@@ -331,7 +332,7 @@ export const TableEditor = (props) => {
331
332
  const site = useContext(SiteContext)
332
333
  const [pageContext, setPageContext] = useContext(PageContext)
333
334
  const { all = [], filters } = pageContext
334
- const { icon, title, schema, editable, canDelete, filter, actions, className, tabbedBy } = props
335
+ const { icon, title, schema, editable, canDelete, filter, actions, className, tabbedBy, sortedBy } = props
335
336
  const [groupBy, setGroupBy] = useState(props.groupBy)
336
337
  const [tab, setTab] = useState(0)
337
338
 
@@ -456,7 +457,7 @@ export const TableEditor = (props) => {
456
457
  return groups
457
458
  }, {})
458
459
 
459
- const sections = Object.keys(groups).map(groupName => {
460
+ const sections = Object.keys(groups).sort().map(groupName => {
460
461
 
461
462
  const rows = groups[groupName].map(item => {
462
463
  item.checked = pageContext.checked ? pageContext.checked.has(item.id) : false
@@ -469,6 +470,16 @@ export const TableEditor = (props) => {
469
470
  return item
470
471
  })
471
472
 
473
+ if (sortedBy) {
474
+ rows.sort((a, b) => {
475
+ const valueA = a[sortedBy]
476
+ const valueB = b[sortedBy]
477
+ if (valueA < valueB) return -1
478
+ if (valueA > valueB) return 1
479
+ return 0
480
+ })
481
+ }
482
+
472
483
  table.rows = rows
473
484
 
474
485
  return ({
@@ -92,6 +92,11 @@
92
92
  background-color: var(--secondary-color-lighter);
93
93
  }
94
94
 
95
+ .content-cell.drag-over {
96
+ background-color: var(--hover-color);
97
+ border: dashed 2px var(--accent-color);
98
+ }
99
+
95
100
  .row-header {
96
101
  position: sticky;
97
102
  left: 0px;
@@ -1,11 +1,12 @@
1
1
  import React, { useEffect, useState } from 'react'
2
2
  import "./planner.css"
3
3
 
4
- export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, rowHeaderWidth = 10, rowHeaderTitle, EventRenderer, onSelectCell, hideEmptyRows=false}) => {
4
+ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, rowHeaderWidth = 10, rowHeaderTitle, EventRenderer, onSelectCell, onCellDrop, hideEmptyRows=false}) => {
5
5
 
6
6
  const [days, setDays] = useState([]);
7
7
  const lastDay = new Date(to);
8
8
  const today = new Date();
9
+ const [dragOverCell, setDragOverCell] = useState(null);
9
10
 
10
11
  useEffect(() => {
11
12
  const day = new Date(from);
@@ -41,10 +42,24 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
41
42
  if (onSelectCell) onSelectCell(cell)
42
43
  }
43
44
 
44
- function drop() {
45
- //TODO
45
+ function onDragOver(event) {
46
+ event.preventDefault();
47
+ setDragOverCell(event.target.id);
46
48
  }
47
49
 
50
+ function onDragLeave(event) {
51
+ event.preventDefault();
52
+ setDragOverCell(null);
53
+ }
54
+
55
+ function drop(event, { lane, date }) {
56
+ event.preventDefault();
57
+ const data = event.dataTransfer.getData("text");
58
+ if (onCellDrop) onCellDrop({ data, lane, date });
59
+ setDragOverCell(null);
60
+ }
61
+
62
+
48
63
  const uniqueMonths = Array.from(
49
64
  new Set(days.map(({ month }) => month))
50
65
  );
@@ -119,7 +134,9 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
119
134
  }
120
135
 
121
136
  return (
122
- <div className={`content-row ${lane.className}`} style={{ width: `${totalDaysWidth}rem` }}>
137
+ <div
138
+ key={`content-row-${index}`}
139
+ className={`content-row ${lane.className}`} style={{ width: `${totalDaysWidth}rem` }}>
123
140
  <div className="row-header" style={{ minWidth: `${rowHeaderWidth}rem`, maxWidth: `${rowHeaderWidth}rem` }} >
124
141
  {lane.title}
125
142
  </div>
@@ -132,12 +149,15 @@ export const Planner2 = ({ from, to, lanes = [], events = [], cellWidth = 10, ro
132
149
  eventDate.getFullYear() === dayDate.getFullYear();
133
150
  });
134
151
  const weekendClass = isWeekend ? 'weekend' : '';
152
+ const dragOverStyle = dragOverCell === `cell${index}_${year}-${month}-${day}` ? 'drag-over' : '';
135
153
  return (
136
154
  <div
155
+ id={`cell${index}_${year}-${month}-${day}`}
137
156
  key={`content${index}_${year}-${month}-${day}`}
138
- className={`content-cell ${weekendClass}`} style={{ minWidth: dayWidth, maxWidth: dayWidth }}
157
+ className={`content-cell ${weekendClass} ${dragOverStyle}`} style={{ minWidth: dayWidth, maxWidth: dayWidth }}
139
158
  onClick={() => selectCell({ lane: lane.id, date: dayDate })}
140
- onDrop={drop}
159
+ onDragOver={onDragOver} onDragLeave={onDragLeave}
160
+ onDrop={(event) => drop(event, { lane: lane.id, date: dayDate })}
141
161
  >
142
162
  {dayEvents.map((event, index) => <EventRenderer key={`${event.id}-${index}`} event={event} />)}
143
163
  </div>
@@ -155,7 +175,7 @@ const EventCard = (props) => {
155
175
  const { id, title, color } = event
156
176
 
157
177
  function drag(ev) {
158
- ev.dataTransfer.setData("text", id);
178
+ ev.dataTransfer.setData("text", title);
159
179
  }
160
180
 
161
181
  let style = { backgroundColor: event.color, color: "white" }
@@ -181,23 +201,19 @@ const CalendarTest = (props) => {
181
201
 
182
202
  const events = [
183
203
  { id: "1", lane: "1", date: "2024-01-04", color: "yellow", title: "Event One" },
184
- { id: "1", lane: "1", date: "2024-01-04", color: "yellow", title: "Event One" },
185
- { id: "1", lane: "1", date: "2024-01-05", color: "yellow", title: "Event One" },
186
- { id: "2", lane: "1", date: "2024-01-05", color: "red", title: "Event One" },
187
- { id: "3", lane: "1", date: "2024-01-05", color: "blue", title: "Event One" },
188
- { id: "4", lane: "1", date: "2024-01-05", color: "red", title: "Event One" },
189
- { id: "5", lane: "2", date: "2024-01-04", color: "yellow", title: "Event One" },
190
- { id: "6", lane: "2", date: "2024-01-05", color: "red", title: "Event One" },
191
- { id: "7", lane: "2", date: "2024-01-06", color: "blue", title: "Event One" },
192
- { id: "8", lane: "2", date: "2024-01-07", color: "red", title: "Event One" },
193
- { id: "9", lane: "3", date: "2024-01-04", color: "yellow", title: "Event One" },
194
- { id: "10", lane: "3", date: "2024-01-05", color: "red", title: "Event One" },
195
- { id: "11", lane: "3", date: "2024-01-06", color: "blue", title: "Event One" },
204
+ { id: "2", lane: "1", date: "2024-01-05", color: "green", title: "Event Two" },
205
+ { id: "3", lane: "2", date: "2024-01-06", color: "blue", title: "Event Three" },
206
+ { id: "4", lane: "2", date: "2024-01-07", color: "red", title: "Event Four" },
207
+ { id: "5", lane: "3", date: "2024-01-08", color: "purple", title: "Event Five" },
196
208
  ]
197
209
 
210
+ function onDrop({ data, lane, date }) {
211
+ console.log(`Dropped ${data} on lane ${lane} date ${date}`);
212
+ }
213
+
198
214
  return (
199
215
  <>
200
- <Planner2 from="2024-01-01" to="2024-02-01" lanes={lanes} events={events} EventRenderer={EventCard} hideEmptyRows />
216
+ <Planner2 from="2024-01-01" to="2024-02-01" lanes={lanes} events={events} EventRenderer={EventCard} hideEmptyRows onCellDrop={onDrop} />
201
217
  </>
202
218
  )
203
219
  }
package/src/site/site.css CHANGED
@@ -42,6 +42,7 @@
42
42
  flex-direction: column;
43
43
  overflow: hidden;
44
44
  width: var(--site-menu-width);
45
+ transition: width 0.3s ease-in-out;
45
46
  }
46
47
 
47
48
  .site6>menu>header {
@@ -53,6 +54,7 @@
53
54
  }
54
55
 
55
56
  .site6>menu.min {
57
+ width: var(--site-menu-width);
56
58
  overflow: visible;
57
59
  }
58
60