@vertly/dashboard-grid 0.1.0 → 0.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/README.md CHANGED
@@ -43,6 +43,60 @@ yourself (e.g. server-side, or in a parent Server Component) and pass the
43
43
  result down, rather than having this component fetch or render widget data
44
44
  itself.
45
45
 
46
+ ## Adding or removing a widget
47
+
48
+ `DashboardGrid` only manages layout state (row order, row heights, each
49
+ widget's colSpan) internally — it seeds that state from `rows`/`widgets`
50
+ once on mount, then owns it itself as the user drags/resizes/reorders,
51
+ notifying you via `onUpdateLayout`/`onDeleteWidget` rather than re-reading
52
+ it back from your props. That means **updating `rows`/`widgets` alone,
53
+ after the initial mount, does not make an added or removed widget appear**
54
+ — the mounted instance never re-seeds from new props.
55
+
56
+ To make an add/remove show up, change the component's `key` (e.g. the
57
+ widget-id set) whenever your data's widget membership changes, so React
58
+ remounts it with a fresh seed:
59
+
60
+ ```tsx
61
+ <DashboardGrid<MyWidget> key={Object.keys(widgets).join(',')} rows={rows} widgets={widgets} ... />
62
+ ```
63
+
64
+ Don't key it on anything that changes on every drag/resize (like colSpan or
65
+ row order) — that would remount mid-interaction and drop the user's
66
+ in-progress drag.
67
+
68
+ ## Adding a widget by dragging it in
69
+
70
+ To let users drag a widget in from outside the grid (e.g. a palette of
71
+ widget kinds), give your palette items' `useDrag` the exported
72
+ `EXTERNAL_ITEM_TYPE` as their `type`, and pass `onDropExternalItem` (dropped
73
+ into an existing row) and/or `onCreateRowExternalItem` (dropped on the
74
+ "start a new row" zone) — the grid's own drop zones accept that type
75
+ alongside its internal widget drags once either prop is provided, and hand
76
+ you back the raw dragged item plus where it landed:
77
+
78
+ ```tsx
79
+ import { DashboardGrid, EXTERNAL_ITEM_TYPE } from '@vertly/dashboard-grid';
80
+ import { useDrag } from 'react-dnd';
81
+
82
+ function PaletteItem({ kind }: { kind: string }) {
83
+ const [, dragRef] = useDrag(() => ({ type: EXTERNAL_ITEM_TYPE, item: { kind } }));
84
+ return <div ref={dragRef}>{kind}</div>;
85
+ }
86
+
87
+ <DashboardGrid<MyWidget>
88
+ rows={rows}
89
+ widgets={widgets}
90
+ onDropExternalItem={(item, rowId, index) => spawnWidget(item as { kind: string }, rowId, index)}
91
+ onCreateRowExternalItem={(item) => spawnWidgetInNewRow(item as { kind: string })}
92
+ />;
93
+ ```
94
+
95
+ This component never inspects the dragged item's shape — it's whatever
96
+ your palette's `useDrag` supplied, passed straight through. As with any
97
+ other add, remember to re-key the component once the new widget lands in
98
+ your `rows`/`widgets` data (see above).
99
+
46
100
  ## Layout math
47
101
 
48
102
  The row/column layout functions the component is built on
@@ -68,5 +122,5 @@ relevant selectors in your own global CSS.
68
122
 
69
123
  See `DashboardGridProps` in the package's type definitions for the full
70
124
  list: `rows`, `widgets`, `readOnly`, `saveDebounceMs`, `onUpdateLayout`,
71
- `onDeleteWidget`, `renderRowEdgeAdd`, `renderWidgetMenu`,
72
- `renderWidgetConfigDialog`.
125
+ `onDeleteWidget`, `onDropExternalItem`, `onCreateRowExternalItem`,
126
+ `renderRowEdgeAdd`, `renderWidgetMenu`, `renderWidgetConfigDialog`.
package/dist/cn.cjs ADDED
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var cn_exports = {};
20
+ __export(cn_exports, {
21
+ cn: () => cn
22
+ });
23
+ module.exports = __toCommonJS(cn_exports);
24
+ var import_clsx = require("clsx");
25
+ var import_tailwind_merge = require("tailwind-merge");
26
+ function cn(...inputs) {
27
+ return (0, import_tailwind_merge.twMerge)((0, import_clsx.clsx)(inputs));
28
+ }
29
+ // Annotate the CommonJS export names for ESM import in node:
30
+ 0 && (module.exports = {
31
+ cn
32
+ });
33
+ //# sourceMappingURL=cn.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAsC;AACtC,4BAAwB;AAEjB,SAAS,MAAM,QAAsB;AAC1C,aAAO,mCAAQ,kBAAK,MAAM,CAAC;AAC7B;","names":[]}
package/dist/cn.d.cts ADDED
@@ -0,0 +1,5 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ declare function cn(...inputs: ClassValue[]): string;
4
+
5
+ export { cn };
package/dist/cn.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { ClassValue } from 'clsx';
2
+
3
+ declare function cn(...inputs: ClassValue[]): string;
4
+
5
+ export { cn };
package/dist/cn.js ADDED
@@ -0,0 +1,9 @@
1
+ import { clsx } from "clsx";
2
+ import { twMerge } from "tailwind-merge";
3
+ function cn(...inputs) {
4
+ return twMerge(clsx(inputs));
5
+ }
6
+ export {
7
+ cn
8
+ };
9
+ //# sourceMappingURL=cn.js.map
package/dist/cn.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/cn.ts"],"sourcesContent":["import { clsx, type ClassValue } from 'clsx';\nimport { twMerge } from 'tailwind-merge';\n\nexport function cn(...inputs: ClassValue[]) {\n return twMerge(clsx(inputs));\n}\n"],"mappings":"AAAA,SAAS,YAA6B;AACtC,SAAS,eAAe;AAEjB,SAAS,MAAM,QAAsB;AAC1C,SAAO,QAAQ,KAAK,MAAM,CAAC;AAC7B;","names":[]}