@logimaxx/kgrid 0.2.3 → 0.4.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 +4 -1
- package/dist/kgrid.js +891 -67
- package/dist/kgrid.min.js +2 -2
- package/docs/ai-guide.md +15 -6
- package/docs/api.md +20 -4
- package/docs/configuration.md +32 -4
- package/docs/field-types.md +22 -0
- package/docs/release.md +180 -0
- package/docs/table-shell.md +1 -0
- package/integrations/maxxops.example.js +0 -1
- package/package.json +1 -1
- package/src/cells.js +19 -1
- package/src/column-chooser.js +155 -0
- package/src/configure.js +66 -15
- package/src/constants.js +13 -1
- package/src/data-body.js +47 -30
- package/src/dom.js +41 -5
- package/src/events.js +17 -0
- package/src/filters.js +37 -2
- package/src/init.js +67 -4
- package/src/insert-row.js +14 -7
- package/src/interaction.js +4 -1
- package/src/preferences.js +404 -0
- package/styles/table.css +94 -6
package/docs/release.md
ADDED
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# Release guide
|
|
2
|
+
|
|
3
|
+
Maintainer-only process for shipping **`@logimaxx/kgrid`**. The package is proprietary (Logimaxx System SRL); distribution is controlled, but `publishConfig.access` is `public` so authorized npm publishes succeed.
|
|
4
|
+
|
|
5
|
+
Related: [CONTRIBUTING.md](../CONTRIBUTING.md), [NOTICE.md](../NOTICE.md), `scripts/release.mjs`, `version.sh`.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Who can release
|
|
10
|
+
|
|
11
|
+
Only maintainers with:
|
|
12
|
+
|
|
13
|
+
- Write access to `github.com/logimaxx/kgrid`
|
|
14
|
+
- npm publish rights for the `@logimaxx` scope
|
|
15
|
+
- Permission to push tags to the default branch
|
|
16
|
+
|
|
17
|
+
Contact: [sergiu@logimaxx.ro](mailto:sergiu@logimaxx.ro).
|
|
18
|
+
|
|
19
|
+
---
|
|
20
|
+
|
|
21
|
+
## Prerequisites
|
|
22
|
+
|
|
23
|
+
1. Clean working tree for everything you intend to ship (except intentional `dist/` refresh — see below).
|
|
24
|
+
2. On the release branch (usually `main`), up to date with remote.
|
|
25
|
+
3. Logged in to npm as a user that can publish `@logimaxx/kgrid`:
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
npm whoami
|
|
29
|
+
npm access list packages @logimaxx # or your org’s equivalent check
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
4. Do **not** set `"private": true` in `package.json`. That causes `npm publish` to fail with `EPRIVATE`. Access control is via registry permissions and who you grant installs to — not the `private` flag.
|
|
33
|
+
|
|
34
|
+
---
|
|
35
|
+
|
|
36
|
+
## Versioning
|
|
37
|
+
|
|
38
|
+
Use [semver](https://semver.org/):
|
|
39
|
+
|
|
40
|
+
| Bump | When |
|
|
41
|
+
|------|------|
|
|
42
|
+
| **patch** | Bug fixes, docs-only package tweaks, no API shape change |
|
|
43
|
+
| **minor** | New features / options that stay backward compatible |
|
|
44
|
+
| **major** | Breaking API, required config changes, or peer-dep jumps that break hosts |
|
|
45
|
+
|
|
46
|
+
Current version lives in `package.json` (`version`). `npm version` / `./version.sh` bump it and create a matching git tag (`vX.Y.Z`).
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## What gets published
|
|
51
|
+
|
|
52
|
+
From `package.json` `files`:
|
|
53
|
+
|
|
54
|
+
| Path | Role |
|
|
55
|
+
|------|------|
|
|
56
|
+
| `dist/` | Bundles (`kgrid.js`, `kgrid.min.js`) — **commit these** before tagging |
|
|
57
|
+
| `src/` | Source |
|
|
58
|
+
| `styles/` | Required CSS (`table.css`) |
|
|
59
|
+
| `docs/` | Human + AI docs |
|
|
60
|
+
| `integrations/` | Optional widgets (e.g. `kgrid-widgets.js`) |
|
|
61
|
+
| `LICENSE`, `NOTICE.md`, `AGENTS.md` | Legal / branding |
|
|
62
|
+
|
|
63
|
+
`prepare` runs `npm run build` on install; still treat committed `dist/` as the release artifact so git-tag consumers get a ready tree.
|
|
64
|
+
|
|
65
|
+
---
|
|
66
|
+
|
|
67
|
+
## Release checklist
|
|
68
|
+
|
|
69
|
+
### 1. Finish the change set
|
|
70
|
+
|
|
71
|
+
- [ ] Tests cover non-trivial logic (`test/`)
|
|
72
|
+
- [ ] Docs under `docs/` updated if public API or behavior changed
|
|
73
|
+
- [ ] Peer deps (`jquery`, `@logimaxx/kviews`) still accurate
|
|
74
|
+
- [ ] Demo smoke-check if UI/CRUD changed: `npm run demo`
|
|
75
|
+
|
|
76
|
+
### 2. Prep (test + build)
|
|
77
|
+
|
|
78
|
+
```bash
|
|
79
|
+
npm run release
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
This runs `npm test` and `npm run build`, then reports whether `dist/` differs from the index.
|
|
83
|
+
|
|
84
|
+
If `dist/` is dirty:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
git add dist
|
|
88
|
+
git commit -m "chore: refresh dist"
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
`npm version` requires a clean tree for the files it touches; commit dist (and any other release files) first.
|
|
92
|
+
|
|
93
|
+
### 3. Bump, tag, push
|
|
94
|
+
|
|
95
|
+
Preferred (Unix):
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
./version.sh patch # or: minor | major
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
That runs:
|
|
102
|
+
|
|
103
|
+
1. `npm version <bump>` — updates `package.json` (+ lockfile if present), commits, tags
|
|
104
|
+
2. `git push`
|
|
105
|
+
3. `git push --tags`
|
|
106
|
+
|
|
107
|
+
Manual equivalent:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
npm version patch # or minor | major
|
|
111
|
+
git push && git push --tags
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 4. Publish to npm
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
npm publish
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Scoped package name: `@logimaxx/kgrid`. Confirm the published version on the registry before notifying consumers.
|
|
121
|
+
|
|
122
|
+
### 5. After publish
|
|
123
|
+
|
|
124
|
+
- [ ] Spot-check install in a host app (or MaxxOps alias — see below)
|
|
125
|
+
- [ ] Note the version in release chat / ticket if the team uses one
|
|
126
|
+
- [ ] If hosts pin ranges (`^0.2.2`), confirm they can resolve the new version
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
## Consumer install
|
|
131
|
+
|
|
132
|
+
```bash
|
|
133
|
+
npm install @logimaxx/kgrid @logimaxx/kviews jquery
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
MaxxOps-style folder alias (keeps `node_modules/kgrid/`):
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npm install kgrid@npm:@logimaxx/kgrid@^0.2.2
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
Alternatives (authorized access required):
|
|
143
|
+
|
|
144
|
+
```bash
|
|
145
|
+
npm install github:logimaxx/kgrid#v0.2.4 # or #main
|
|
146
|
+
npm install file:../kgrid
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
---
|
|
150
|
+
|
|
151
|
+
## One-liner flow (happy path)
|
|
152
|
+
|
|
153
|
+
```bash
|
|
154
|
+
# on main, changes already merged and reviewed
|
|
155
|
+
npm run release
|
|
156
|
+
# if dist dirty: commit as above, then:
|
|
157
|
+
./version.sh patch
|
|
158
|
+
npm publish
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
---
|
|
162
|
+
|
|
163
|
+
## Troubleshooting
|
|
164
|
+
|
|
165
|
+
| Symptom | Fix |
|
|
166
|
+
|---------|-----|
|
|
167
|
+
| `npm version` refuses (dirty tree) | Commit or stash; especially commit refreshed `dist/` |
|
|
168
|
+
| `EPRIVATE` on publish | Remove `"private": true`; keep `publishConfig.access: "public"` |
|
|
169
|
+
| `ENEEDAUTH` / 403 | `npm login` with a user that can publish `@logimaxx` |
|
|
170
|
+
| Tag already exists | Do not force-retag casually; bump again or delete the mistaken local tag only if it was never pushed |
|
|
171
|
+
| Consumers still on old code | They may pin exact versions or use a stale lockfile — bump their dependency range / reinstall |
|
|
172
|
+
|
|
173
|
+
---
|
|
174
|
+
|
|
175
|
+
## Do not
|
|
176
|
+
|
|
177
|
+
- Publish from a dirty or untested tree
|
|
178
|
+
- Skip committing `dist/` when the build changed bundles
|
|
179
|
+
- Force-push release tags on shared remotes without maintainer agreement
|
|
180
|
+
- Suggest open-sourcing or changing the license as part of a routine release
|
package/docs/table-shell.md
CHANGED
|
@@ -16,6 +16,7 @@ After `npm install`, the template is inside the built bundle (`dist/kgrid.js`).
|
|
|
16
16
|
|
|
17
17
|
```
|
|
18
18
|
.custom-table-shell ← class added on host if missing
|
|
19
|
+
.kgrid-column-chooser ← when features.columnChooser
|
|
19
20
|
table.custom-table
|
|
20
21
|
colgroup.kgrid-colgroup ← injected at init (data cols + optional row-actions col)
|
|
21
22
|
thead.thead-labels ← one <th> template; cloned per column in labels.js
|
|
@@ -6,7 +6,6 @@ KGrid.configure({
|
|
|
6
6
|
log: typeof klog === "function" ? klog : console.log.bind(console),
|
|
7
7
|
onError: modal_error,
|
|
8
8
|
confirm: modal_confirm,
|
|
9
|
-
serializeForm: serializeFormData2,
|
|
10
9
|
customInputTypes: {
|
|
11
10
|
select2: KGrid.select2(select2wrapper),
|
|
12
11
|
autosuggest: KGrid.autosuggest(function ($input, options) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@logimaxx/kgrid",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "KGrid — declarative data table for KViews (filter, sort, paging, inline CRUD). Proprietary — Logimaxx System SRL.",
|
|
5
5
|
"main": "dist/kgrid.js",
|
|
6
6
|
"homepage": "https://logimaxx.ro",
|
package/src/cells.js
CHANGED
|
@@ -1,4 +1,17 @@
|
|
|
1
1
|
(function (CT) {
|
|
2
|
+
/**
|
|
3
|
+
* Bootstrap switch wrapper around a checkbox used as a boolean flag.
|
|
4
|
+
* @param {JQuery} $input
|
|
5
|
+
* @returns {JQuery} wrapper
|
|
6
|
+
*/
|
|
7
|
+
CT.wrapFlagSwitch = function ($input) {
|
|
8
|
+
$input
|
|
9
|
+
.attr({ type: "checkbox", role: "switch", value: "1" })
|
|
10
|
+
.removeClass("form-control form-input form-control-sm")
|
|
11
|
+
.addClass("form-check-input");
|
|
12
|
+
return $("<div class='form-check form-switch kgrid-flag-switch mb-0'>").append($input);
|
|
13
|
+
};
|
|
14
|
+
|
|
2
15
|
/**
|
|
3
16
|
* Setup data cell
|
|
4
17
|
* @param {Object} col
|
|
@@ -68,6 +81,10 @@
|
|
|
68
81
|
$("<div>").addClass("cell-input").append(tpl).appendTo($cell);
|
|
69
82
|
return $cell;
|
|
70
83
|
}
|
|
84
|
+
case "checkbox":
|
|
85
|
+
input = $("<input autocomplete='off' type='checkbox' class='form-check-input'/>");
|
|
86
|
+
skipValueAttr = true;
|
|
87
|
+
break;
|
|
71
88
|
default:
|
|
72
89
|
if(CT.isValidInputType(updateType)) {
|
|
73
90
|
input = $(`<input autocomplete='off' type='${updateType}' class='form-input form-control form-control-sm'/>`);
|
|
@@ -107,7 +124,8 @@
|
|
|
107
124
|
if(!updateConfig.disabled && !updateConfig.readonly)
|
|
108
125
|
input.attr("onchange","$(this).parents('tr').addClass('editing')");
|
|
109
126
|
|
|
110
|
-
$
|
|
127
|
+
const $control = updateType === "checkbox" ? CT.wrapFlagSwitch(input) : input;
|
|
128
|
+
$("<div>").addClass("cell-input").append($control).appendTo($cell);
|
|
111
129
|
return $cell;
|
|
112
130
|
};
|
|
113
131
|
})(window.KGrid);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Column chooser: checkbox visibility + HTML5 drag reorder.
|
|
3
|
+
*/
|
|
4
|
+
(function (CT) {
|
|
5
|
+
function layoutFromPanel($panel) {
|
|
6
|
+
const columns = [];
|
|
7
|
+
$panel.find(".kgrid-column-chooser-list li[data-name]").each(function () {
|
|
8
|
+
const name = this.getAttribute("data-name");
|
|
9
|
+
const checked = $(this).find("input[type='checkbox']").prop("checked");
|
|
10
|
+
columns.push({ name: name, hidden: !checked });
|
|
11
|
+
});
|
|
12
|
+
return { v: CT.PREFERENCES_VERSION, columns: columns };
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function visibleCount(layout) {
|
|
16
|
+
return layout.columns.filter(function (c) {
|
|
17
|
+
return !c.hidden;
|
|
18
|
+
}).length;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
CT.renderColumnChooserPanel = function ($panel, options, api) {
|
|
22
|
+
$panel.empty();
|
|
23
|
+
const $list = $("<ul>").addClass("kgrid-column-chooser-list").appendTo($panel);
|
|
24
|
+
CT.chooserColumns(options.columns).forEach(function (col) {
|
|
25
|
+
const $li = $("<li>")
|
|
26
|
+
.attr("draggable", "true")
|
|
27
|
+
.attr("data-name", col.name)
|
|
28
|
+
.appendTo($list);
|
|
29
|
+
$("<span>")
|
|
30
|
+
.addClass("kgrid-column-chooser-handle")
|
|
31
|
+
.attr("aria-hidden", "true")
|
|
32
|
+
.text("⋮⋮")
|
|
33
|
+
.appendTo($li);
|
|
34
|
+
const $label = $("<label>").appendTo($li);
|
|
35
|
+
const $cb = $("<input>")
|
|
36
|
+
.attr("type", "checkbox")
|
|
37
|
+
.prop("checked", !col.userHidden)
|
|
38
|
+
.appendTo($label);
|
|
39
|
+
if (col.locked) {
|
|
40
|
+
$cb.prop("disabled", true).attr("title", "This column cannot be hidden");
|
|
41
|
+
}
|
|
42
|
+
$label.append(document.createTextNode(" " + (col.label || col.name)));
|
|
43
|
+
});
|
|
44
|
+
$("<button>")
|
|
45
|
+
.attr("type", "button")
|
|
46
|
+
.addClass("btn btn-sm btn-outline-secondary kgrid-column-chooser-reset")
|
|
47
|
+
.text(options.columnChooserResetLabel || "Reset columns")
|
|
48
|
+
.appendTo($panel);
|
|
49
|
+
|
|
50
|
+
$panel
|
|
51
|
+
.off("change.kgridChooser")
|
|
52
|
+
.on("change.kgridChooser", "input[type='checkbox']", function () {
|
|
53
|
+
const layout = layoutFromPanel($panel);
|
|
54
|
+
if (visibleCount(layout) < 1) {
|
|
55
|
+
this.checked = true;
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
api.setLayout(layout);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
$panel
|
|
62
|
+
.off("click.kgridChooserReset")
|
|
63
|
+
.on("click.kgridChooserReset", ".kgrid-column-chooser-reset", function () {
|
|
64
|
+
api.resetLayout();
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
let dragEl = null;
|
|
68
|
+
$list.off(".kgridChooserDrag");
|
|
69
|
+
$list.on("dragstart.kgridChooserDrag", "li", function (e) {
|
|
70
|
+
dragEl = this;
|
|
71
|
+
$(this).addClass("kgrid-column-chooser-dragging");
|
|
72
|
+
if (e.originalEvent && e.originalEvent.dataTransfer) {
|
|
73
|
+
e.originalEvent.dataTransfer.effectAllowed = "move";
|
|
74
|
+
e.originalEvent.dataTransfer.setData("text/plain", this.getAttribute("data-name"));
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
$list.on("dragend.kgridChooserDrag", "li", function () {
|
|
78
|
+
$(this).removeClass("kgrid-column-chooser-dragging");
|
|
79
|
+
dragEl = null;
|
|
80
|
+
});
|
|
81
|
+
$list.on("dragover.kgridChooserDrag", "li", function (e) {
|
|
82
|
+
e.preventDefault();
|
|
83
|
+
if (!dragEl || dragEl === this) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
const rect = this.getBoundingClientRect();
|
|
87
|
+
const mid = rect.top + rect.height / 2;
|
|
88
|
+
const clientY = e.originalEvent ? e.originalEvent.clientY : 0;
|
|
89
|
+
if (clientY < mid) {
|
|
90
|
+
this.parentNode.insertBefore(dragEl, this);
|
|
91
|
+
} else {
|
|
92
|
+
this.parentNode.insertBefore(dragEl, this.nextSibling);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
$list.on("drop.kgridChooserDrag", "li", function (e) {
|
|
96
|
+
e.preventDefault();
|
|
97
|
+
api.setLayout(layoutFromPanel($panel));
|
|
98
|
+
});
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
CT.setupColumnChooser = function ($host, options, api) {
|
|
102
|
+
if (!options.features || !options.features.columnChooser) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const $shell = CT.getTableInteractionHost($host);
|
|
106
|
+
$shell.find(".kgrid-column-chooser").remove();
|
|
107
|
+
const label = options.columnChooserLabel || "Columns";
|
|
108
|
+
const $wrap = $("<div>").addClass("kgrid-column-chooser");
|
|
109
|
+
const $btn = $("<button>")
|
|
110
|
+
.attr("type", "button")
|
|
111
|
+
.addClass("kgrid-column-chooser-toggle btn btn-sm btn-outline-secondary")
|
|
112
|
+
.attr("title", label)
|
|
113
|
+
.attr("aria-expanded", "false")
|
|
114
|
+
.attr("aria-haspopup", "true")
|
|
115
|
+
.html(
|
|
116
|
+
'<i class="fas fa-table-columns" aria-hidden="true"></i>' +
|
|
117
|
+
'<span class="kgrid-column-chooser-toggle-label"> ' +
|
|
118
|
+
$("<div>").text(label).html() +
|
|
119
|
+
"</span>"
|
|
120
|
+
);
|
|
121
|
+
const $panel = $("<div>")
|
|
122
|
+
.addClass("kgrid-column-chooser-panel")
|
|
123
|
+
.attr("hidden", "hidden");
|
|
124
|
+
$wrap.append($btn, $panel);
|
|
125
|
+
$shell.prepend($wrap);
|
|
126
|
+
CT.renderColumnChooserPanel($panel, options, api);
|
|
127
|
+
|
|
128
|
+
function close() {
|
|
129
|
+
$panel.attr("hidden", "hidden");
|
|
130
|
+
$btn.attr("aria-expanded", "false");
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
$btn.on("click", function (e) {
|
|
134
|
+
e.stopPropagation();
|
|
135
|
+
const open = !$panel.attr("hidden");
|
|
136
|
+
if (open) {
|
|
137
|
+
close();
|
|
138
|
+
} else {
|
|
139
|
+
$panel.removeAttr("hidden");
|
|
140
|
+
$btn.attr("aria-expanded", "true");
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
const ns = "kgridChooser" + CT.uuid();
|
|
145
|
+
$(document).on("pointerdown." + ns, function (e) {
|
|
146
|
+
if (!document.body.contains($wrap[0])) {
|
|
147
|
+
$(document).off("pointerdown." + ns);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
if (!$wrap[0].contains(e.target)) {
|
|
151
|
+
close();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
})(window.KGrid);
|
package/src/configure.js
CHANGED
|
@@ -2,6 +2,69 @@
|
|
|
2
2
|
* Host-app integration: call KGrid.configure({ ... }) before mounting tables.
|
|
3
3
|
*/
|
|
4
4
|
(function (CT) {
|
|
5
|
+
/**
|
|
6
|
+
* Flag is on when the API/form value is true, 1, or "1".
|
|
7
|
+
* @param {*} v
|
|
8
|
+
* @returns {boolean}
|
|
9
|
+
*/
|
|
10
|
+
CT.isFlagOn = function (v) {
|
|
11
|
+
return v === true || v === 1 || v === "1";
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Walk form.elements (includes fields associated via form="id").
|
|
16
|
+
* Checkboxes always emit "1" or "0" — FormData omits unchecked boxes.
|
|
17
|
+
* @param {HTMLFormElement} form
|
|
18
|
+
* @returns {Record<string, *>}
|
|
19
|
+
*/
|
|
20
|
+
function defaultSerializeForm(form) {
|
|
21
|
+
const out = {};
|
|
22
|
+
const els = form && form.elements;
|
|
23
|
+
if (!els) {
|
|
24
|
+
return out;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < els.length; i++) {
|
|
27
|
+
const el = els[i];
|
|
28
|
+
const name = el.name;
|
|
29
|
+
if (!name || el.disabled) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const type = el.type;
|
|
33
|
+
if (type === "submit" || type === "button" || type === "reset" || type === "file") {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
if (type === "checkbox") {
|
|
37
|
+
out[name] = el.checked ? "1" : "0";
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
if (type === "radio") {
|
|
41
|
+
if (!el.checked) {
|
|
42
|
+
continue;
|
|
43
|
+
}
|
|
44
|
+
out[name] = el.value;
|
|
45
|
+
continue;
|
|
46
|
+
}
|
|
47
|
+
if (el.tagName === "SELECT" && el.multiple) {
|
|
48
|
+
out[name] = Array.from(el.selectedOptions).map(function (o) {
|
|
49
|
+
return o.value;
|
|
50
|
+
});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
const value = el.value;
|
|
54
|
+
if (Object.prototype.hasOwnProperty.call(out, name)) {
|
|
55
|
+
if (!Array.isArray(out[name])) {
|
|
56
|
+
out[name] = [out[name]];
|
|
57
|
+
}
|
|
58
|
+
out[name].push(value);
|
|
59
|
+
} else {
|
|
60
|
+
out[name] = value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return out;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
CT.serializeFormDefault = defaultSerializeForm;
|
|
67
|
+
|
|
5
68
|
const defaultConfig = {
|
|
6
69
|
log: function () {},
|
|
7
70
|
onError: function (err) {
|
|
@@ -16,21 +79,7 @@
|
|
|
16
79
|
},
|
|
17
80
|
/** @type {((context: object, onConfirm: Function, onCancel?: Function) => void)|null} */
|
|
18
81
|
deleteConfirm: null,
|
|
19
|
-
serializeForm:
|
|
20
|
-
const fd = new FormData(form);
|
|
21
|
-
const out = {};
|
|
22
|
-
for (const [key, value] of fd.entries()) {
|
|
23
|
-
if (Object.prototype.hasOwnProperty.call(out, key)) {
|
|
24
|
-
if (!Array.isArray(out[key])) {
|
|
25
|
-
out[key] = [out[key]];
|
|
26
|
-
}
|
|
27
|
-
out[key].push(value);
|
|
28
|
-
} else {
|
|
29
|
-
out[key] = value;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return out;
|
|
33
|
-
},
|
|
82
|
+
serializeForm: defaultSerializeForm,
|
|
34
83
|
/** @type {Record<string, Function|object>|null} name → wrapper fn or field type plugin */
|
|
35
84
|
customInputTypes: null,
|
|
36
85
|
/** @deprecated use customInputTypes */
|
|
@@ -39,6 +88,8 @@
|
|
|
39
88
|
kviews: null,
|
|
40
89
|
/** Default delay (ms) before filter submit; 0 = immediate. Applies to the resolved filter-submit event. */
|
|
41
90
|
filterDebounceMs: 300,
|
|
91
|
+
/** { get(key), set(key, value|null) } — null uses localStorage */
|
|
92
|
+
preferencesStorage: null,
|
|
42
93
|
};
|
|
43
94
|
|
|
44
95
|
CT._config = Object.assign({}, defaultConfig);
|
package/src/constants.js
CHANGED
|
@@ -12,8 +12,16 @@
|
|
|
12
12
|
"paging": false,
|
|
13
13
|
"create": false,
|
|
14
14
|
"update": false,
|
|
15
|
-
"delete": false
|
|
15
|
+
"delete": false,
|
|
16
|
+
"clone": false,
|
|
17
|
+
"columnChooser": false
|
|
16
18
|
},
|
|
19
|
+
/** Persist key for layout (and filters). Required for localStorage. */
|
|
20
|
+
storageKey: null,
|
|
21
|
+
/** Extra suffix for saved filters only (e.g. company id). Layout ignores this. */
|
|
22
|
+
filterStorageScope: null,
|
|
23
|
+
columnChooserLabel: "Columns",
|
|
24
|
+
columnChooserResetLabel: "Reset columns",
|
|
17
25
|
"defaultInteraction": "view",
|
|
18
26
|
"insertFormRow": {
|
|
19
27
|
"position": "top"
|
|
@@ -40,6 +48,10 @@
|
|
|
40
48
|
label: null,
|
|
41
49
|
name: null,
|
|
42
50
|
hidden: false,
|
|
51
|
+
/** When true, column chooser cannot hide this column (still reorderable). */
|
|
52
|
+
locked: false,
|
|
53
|
+
/** Runtime: user hid this column via chooser. Not a schema flag. */
|
|
54
|
+
userHidden: false,
|
|
43
55
|
/** CSS class(es) on header/filter/data/insert cells (alias: columnClass) */
|
|
44
56
|
class: null,
|
|
45
57
|
columnClass: null,
|
package/src/data-body.js
CHANGED
|
@@ -9,38 +9,16 @@
|
|
|
9
9
|
return td;
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
/**
|
|
13
|
+
* Fill a data <tr> with cells + optional row-actions (KViews item template).
|
|
14
|
+
* @param {JQuery} dataRow
|
|
15
|
+
* @param {Object} options
|
|
16
|
+
* @returns {JQuery} dataRow
|
|
17
|
+
*/
|
|
18
|
+
CT.fillDataRow = function (dataRow, options) {
|
|
13
19
|
const columns = [...options.columns];
|
|
14
|
-
const dataRow = $("<tr>").appendTo(dataBody);
|
|
15
|
-
if(options.dataRowAttrs && typeof options.dataRowAttrs!=="object") {
|
|
16
|
-
throw new Error("options.dataRowAttrs must be an object");
|
|
17
|
-
}
|
|
18
|
-
const dataRowAttrs = {...(options.dataRowAttrs ?? {})};
|
|
19
|
-
Object.keys(dataRowAttrs).forEach(attr => dataRow.attr(attr,dataRowAttrs[attr]));
|
|
20
|
-
|
|
21
|
-
{
|
|
22
|
-
dataBody.data("emptyview",noDataTbody);
|
|
23
|
-
|
|
24
|
-
if(options?.features?.sorting) {
|
|
25
|
-
dataBody.data("sort",labelsRow);
|
|
26
|
-
}
|
|
27
|
-
if(pagingFooter) {
|
|
28
|
-
dataBody.data("paging",pagingFooter.find(".pages"))
|
|
29
|
-
.data("pagesizeinp",pagingFooter.find(".pagesize"))
|
|
30
|
-
.data("totalrecscount",pagingFooter.find(".totalrecscount"));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
if(filterForm) {
|
|
34
|
-
dataBody.data("filter",filterForm);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
if(options.type) {
|
|
38
|
-
dataBody.data("type",options.type);
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
|
|
42
20
|
const dataRowFormId = "data_row_form_"+CT.uuid()+"_{{this.id}}";
|
|
43
|
-
const editForm = options.features.update
|
|
21
|
+
const editForm = options.features && options.features.update
|
|
44
22
|
? $("<form class='edit-form table-row-form'>").attr("id", dataRowFormId)
|
|
45
23
|
: null;
|
|
46
24
|
|
|
@@ -53,6 +31,13 @@
|
|
|
53
31
|
|
|
54
32
|
if (CT.hasActionColumn(options)) {
|
|
55
33
|
const buttonColumn = $("<td>").addClass("kgrid-row-actions").appendTo(dataRow);
|
|
34
|
+
if(options.features.clone) {
|
|
35
|
+
$("<div>").addClass("btn-group clone-item-grp").appendTo(buttonColumn).append(
|
|
36
|
+
$("<button>").addClass("btn btn-sm btn-outline-secondary clone-item")
|
|
37
|
+
.attr("type","button")
|
|
38
|
+
.attr("title","Clone item")
|
|
39
|
+
.append("<i class='fa-regular fa-copy'></i>"));
|
|
40
|
+
}
|
|
56
41
|
if(options.features.delete) {
|
|
57
42
|
$("<div>").addClass("btn-group delete-item-grp").appendTo(buttonColumn).append(
|
|
58
43
|
$("<button>").addClass("btn btn-sm btn-danger delete-item")
|
|
@@ -83,7 +68,39 @@
|
|
|
83
68
|
if (editForm) {
|
|
84
69
|
CT.anchorRowForm(editForm, dataRow);
|
|
85
70
|
}
|
|
71
|
+
return dataRow;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
CT.setupDataBody = function (dataBody, options, labelsRow, filterForm, pagingFooter, noDataTbody) {
|
|
75
|
+
const dataRow = $("<tr>").appendTo(dataBody);
|
|
76
|
+
if(options.dataRowAttrs && typeof options.dataRowAttrs!=="object") {
|
|
77
|
+
throw new Error("options.dataRowAttrs must be an object");
|
|
78
|
+
}
|
|
79
|
+
const dataRowAttrs = {...(options.dataRowAttrs ?? {})};
|
|
80
|
+
Object.keys(dataRowAttrs).forEach(attr => dataRow.attr(attr,dataRowAttrs[attr]));
|
|
81
|
+
|
|
82
|
+
{
|
|
83
|
+
dataBody.data("emptyview",noDataTbody);
|
|
84
|
+
|
|
85
|
+
if(options?.features?.sorting) {
|
|
86
|
+
dataBody.data("sort",labelsRow);
|
|
87
|
+
}
|
|
88
|
+
if(pagingFooter) {
|
|
89
|
+
dataBody.data("paging",pagingFooter.find(".pages"))
|
|
90
|
+
.data("pagesizeinp",pagingFooter.find(".pagesize"))
|
|
91
|
+
.data("totalrecscount",pagingFooter.find(".totalrecscount"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if(filterForm) {
|
|
95
|
+
dataBody.data("filter",filterForm);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if(options.type) {
|
|
99
|
+
dataBody.data("type",options.type);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
86
102
|
|
|
103
|
+
CT.fillDataRow(dataRow, options);
|
|
87
104
|
return dataBody;
|
|
88
105
|
};
|
|
89
106
|
|