@stramien/vue 0.0.0-stage → 0.13.1
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/LICENSE +21 -0
- package/README.md +78 -2
- package/dist/index.d.ts +595 -0
- package/dist/index.js +664 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -3
package/dist/index.js
ADDED
|
@@ -0,0 +1,664 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
import {
|
|
3
|
+
actionsColumn,
|
|
4
|
+
badgeColumn,
|
|
5
|
+
barColumn,
|
|
6
|
+
booleanColumn,
|
|
7
|
+
createBuiltInColumnTypes,
|
|
8
|
+
currencyColumn,
|
|
9
|
+
DEFAULT_LOCALE_TEXT,
|
|
10
|
+
formatLocaleText,
|
|
11
|
+
markVanillaRenderer as markVanillaRenderer2,
|
|
12
|
+
percentColumn,
|
|
13
|
+
plural,
|
|
14
|
+
relativeTimeColumn,
|
|
15
|
+
sparklineColumn,
|
|
16
|
+
VANILLA_RENDERER_SYMBOL as VANILLA_RENDERER_SYMBOL2
|
|
17
|
+
} from "@stramien/core";
|
|
18
|
+
|
|
19
|
+
// src/StramienGrid.ts
|
|
20
|
+
import {
|
|
21
|
+
createGrid,
|
|
22
|
+
markVanillaRenderer,
|
|
23
|
+
VANILLA_RENDERER_SYMBOL
|
|
24
|
+
} from "@stramien/core";
|
|
25
|
+
import {
|
|
26
|
+
camelize,
|
|
27
|
+
defineComponent,
|
|
28
|
+
Fragment,
|
|
29
|
+
h,
|
|
30
|
+
isProxy,
|
|
31
|
+
mergeProps,
|
|
32
|
+
onBeforeUnmount,
|
|
33
|
+
onErrorCaptured,
|
|
34
|
+
onMounted,
|
|
35
|
+
ref,
|
|
36
|
+
shallowRef,
|
|
37
|
+
Teleport,
|
|
38
|
+
toRaw,
|
|
39
|
+
watch
|
|
40
|
+
} from "vue";
|
|
41
|
+
var VANILLA_RENDERER_BRAND = VANILLA_RENDERER_SYMBOL;
|
|
42
|
+
function vanillaRenderer(fn) {
|
|
43
|
+
return markVanillaRenderer(fn);
|
|
44
|
+
}
|
|
45
|
+
function isVueComponentObject(renderer) {
|
|
46
|
+
if (!renderer || typeof renderer !== "object") return false;
|
|
47
|
+
const obj = renderer;
|
|
48
|
+
return typeof obj.render === "function" || typeof obj.setup === "function" || typeof obj.template === "string" || typeof obj.__vccOpts === "object" || typeof obj.__asyncLoader === "function";
|
|
49
|
+
}
|
|
50
|
+
function isVueRenderer(renderer) {
|
|
51
|
+
if (!renderer) return false;
|
|
52
|
+
if (typeof renderer === "function") {
|
|
53
|
+
return !(VANILLA_RENDERER_BRAND in renderer);
|
|
54
|
+
}
|
|
55
|
+
return isVueComponentObject(renderer);
|
|
56
|
+
}
|
|
57
|
+
var declaredPropsCache = /* @__PURE__ */ new WeakMap();
|
|
58
|
+
function declaredPropKeys(comp) {
|
|
59
|
+
if (declaredPropsCache.has(comp)) return declaredPropsCache.get(comp);
|
|
60
|
+
const keys = /* @__PURE__ */ new Set();
|
|
61
|
+
let found = false;
|
|
62
|
+
const seen = /* @__PURE__ */ new Set();
|
|
63
|
+
const visit = (c) => {
|
|
64
|
+
if (!c || typeof c !== "object" || seen.has(c)) return;
|
|
65
|
+
seen.add(c);
|
|
66
|
+
const o = c;
|
|
67
|
+
const p = o.props;
|
|
68
|
+
if (Array.isArray(p)) {
|
|
69
|
+
found = true;
|
|
70
|
+
for (const k of p) if (typeof k === "string") keys.add(camelize(k));
|
|
71
|
+
} else if (p && typeof p === "object") {
|
|
72
|
+
found = true;
|
|
73
|
+
for (const k of Object.keys(p)) keys.add(camelize(k));
|
|
74
|
+
}
|
|
75
|
+
visit(o.__vccOpts);
|
|
76
|
+
visit(o.extends);
|
|
77
|
+
if (Array.isArray(o.mixins)) for (const m of o.mixins) visit(m);
|
|
78
|
+
};
|
|
79
|
+
visit(comp);
|
|
80
|
+
const result = found ? keys : null;
|
|
81
|
+
declaredPropsCache.set(comp, result);
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
var asyncResolveTicks = /* @__PURE__ */ new WeakMap();
|
|
85
|
+
function trackAsyncComponent(comp) {
|
|
86
|
+
if (typeof comp.__asyncLoader !== "function" || comp.__asyncResolved) return;
|
|
87
|
+
let tick = asyncResolveTicks.get(comp);
|
|
88
|
+
if (!tick) {
|
|
89
|
+
const created = ref(0);
|
|
90
|
+
tick = created;
|
|
91
|
+
asyncResolveTicks.set(comp, created);
|
|
92
|
+
try {
|
|
93
|
+
Promise.resolve(comp.__asyncLoader()).then(
|
|
94
|
+
() => {
|
|
95
|
+
created.value += 1;
|
|
96
|
+
},
|
|
97
|
+
() => {
|
|
98
|
+
}
|
|
99
|
+
);
|
|
100
|
+
} catch {
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
void tick.value;
|
|
104
|
+
}
|
|
105
|
+
function componentProps(comp, params) {
|
|
106
|
+
const all = { ...params, params };
|
|
107
|
+
let target = comp;
|
|
108
|
+
if (typeof target.__asyncLoader === "function") {
|
|
109
|
+
if (!target.__asyncResolved) {
|
|
110
|
+
trackAsyncComponent(target);
|
|
111
|
+
return { params };
|
|
112
|
+
}
|
|
113
|
+
target = target.__asyncResolved;
|
|
114
|
+
}
|
|
115
|
+
const vcc = target.__vccOpts;
|
|
116
|
+
if (target.inheritAttrs === false || vcc?.inheritAttrs === false) return all;
|
|
117
|
+
const keys = declaredPropKeys(target);
|
|
118
|
+
const out = {};
|
|
119
|
+
if (!keys) return out;
|
|
120
|
+
for (const key of keys) {
|
|
121
|
+
if (key in all) out[key] = all[key];
|
|
122
|
+
}
|
|
123
|
+
return out;
|
|
124
|
+
}
|
|
125
|
+
var noop = () => {
|
|
126
|
+
};
|
|
127
|
+
function renderFunctionResult(result) {
|
|
128
|
+
if (typeof Node !== "undefined" && result instanceof Node) {
|
|
129
|
+
return h(DomNodeHost, { node: result });
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
var DomNodeHost = defineComponent({
|
|
134
|
+
name: "StDomNodeHost",
|
|
135
|
+
props: {
|
|
136
|
+
node: { type: Object, required: true }
|
|
137
|
+
},
|
|
138
|
+
setup(props) {
|
|
139
|
+
const hostRef = ref(null);
|
|
140
|
+
const detach = (node) => {
|
|
141
|
+
const host = hostRef.value;
|
|
142
|
+
if (host && node && node.parentNode === host) host.removeChild(node);
|
|
143
|
+
};
|
|
144
|
+
onMounted(() => {
|
|
145
|
+
const host = hostRef.value;
|
|
146
|
+
if (host && props.node) host.appendChild(props.node);
|
|
147
|
+
});
|
|
148
|
+
watch(
|
|
149
|
+
() => props.node,
|
|
150
|
+
(node, prev) => {
|
|
151
|
+
detach(prev);
|
|
152
|
+
if (node) hostRef.value?.appendChild(node);
|
|
153
|
+
},
|
|
154
|
+
{ flush: "post" }
|
|
155
|
+
);
|
|
156
|
+
onBeforeUnmount(() => detach(props.node));
|
|
157
|
+
return () => h("span", { ref: hostRef, style: { display: "contents" } });
|
|
158
|
+
}
|
|
159
|
+
});
|
|
160
|
+
var rendererPropsDef = {
|
|
161
|
+
slotFn: { type: Function, required: false },
|
|
162
|
+
renderer: {
|
|
163
|
+
type: [Object, Function, String],
|
|
164
|
+
required: false
|
|
165
|
+
},
|
|
166
|
+
params: { type: Object, required: true }
|
|
167
|
+
};
|
|
168
|
+
var RendererHost = defineComponent({
|
|
169
|
+
name: "StRendererHost",
|
|
170
|
+
props: rendererPropsDef,
|
|
171
|
+
setup(props) {
|
|
172
|
+
return () => {
|
|
173
|
+
const { slotFn, renderer, params } = props;
|
|
174
|
+
if (slotFn) return slotFn(params);
|
|
175
|
+
if (isVueComponentObject(renderer)) {
|
|
176
|
+
return h(renderer, componentProps(renderer, params));
|
|
177
|
+
}
|
|
178
|
+
if (typeof renderer === "function") {
|
|
179
|
+
const all = { ...params, params };
|
|
180
|
+
return renderFunctionResult(
|
|
181
|
+
renderer(all, { attrs: all, slots: {}, emit: noop })
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
var CellErrorBoundary = defineComponent({
|
|
189
|
+
name: "StCellErrorBoundary",
|
|
190
|
+
props: rendererPropsDef,
|
|
191
|
+
setup(props) {
|
|
192
|
+
const failed = ref(false);
|
|
193
|
+
onErrorCaptured((err, _instance, info) => {
|
|
194
|
+
failed.value = true;
|
|
195
|
+
console.error("[stramien] A cell renderer threw an error", err, info);
|
|
196
|
+
return false;
|
|
197
|
+
});
|
|
198
|
+
return () => failed.value ? null : h(RendererHost, {
|
|
199
|
+
slotFn: props.slotFn,
|
|
200
|
+
renderer: props.renderer,
|
|
201
|
+
params: props.params
|
|
202
|
+
});
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
function toRawRows(rows) {
|
|
206
|
+
const raw = toRaw(rows);
|
|
207
|
+
for (let i = 0; i < raw.length; i++) {
|
|
208
|
+
if (isProxy(raw[i])) return raw.map((row) => toRaw(row));
|
|
209
|
+
}
|
|
210
|
+
return raw;
|
|
211
|
+
}
|
|
212
|
+
function createRawRowsMemo() {
|
|
213
|
+
let lastInput;
|
|
214
|
+
let lastOutput;
|
|
215
|
+
return (rows) => {
|
|
216
|
+
if (!rows) return rows;
|
|
217
|
+
if (rows !== lastInput) {
|
|
218
|
+
lastInput = rows;
|
|
219
|
+
lastOutput = toRawRows(rows);
|
|
220
|
+
}
|
|
221
|
+
return lastOutput;
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
function unwrapApiInputs(api) {
|
|
225
|
+
const { applyTransaction, setRowData, setPinnedTopRowData, setPinnedBottomRowData } = api;
|
|
226
|
+
api.applyTransaction = (tx) => {
|
|
227
|
+
const next = { ...tx };
|
|
228
|
+
if (tx.add) next.add = toRawRows(tx.add);
|
|
229
|
+
if (tx.update) next.update = toRawRows(tx.update);
|
|
230
|
+
if (tx.remove) next.remove = toRawRows(tx.remove);
|
|
231
|
+
return applyTransaction(next);
|
|
232
|
+
};
|
|
233
|
+
api.setRowData = (rows) => setRowData(toRawRows(rows));
|
|
234
|
+
api.setPinnedTopRowData = (rows) => setPinnedTopRowData(toRawRows(rows));
|
|
235
|
+
api.setPinnedBottomRowData = (rows) => setPinnedBottomRowData(toRawRows(rows));
|
|
236
|
+
}
|
|
237
|
+
var OPTION_KEYS = [
|
|
238
|
+
"rowData",
|
|
239
|
+
"columnDefs",
|
|
240
|
+
"defaultColDef",
|
|
241
|
+
"columnTypes",
|
|
242
|
+
"rowModelType",
|
|
243
|
+
"serverSideDatasource",
|
|
244
|
+
"masterDetail",
|
|
245
|
+
"detailRowHeight",
|
|
246
|
+
"detailCellRenderer",
|
|
247
|
+
"expandOnRowClick",
|
|
248
|
+
"treeData",
|
|
249
|
+
"treeColumnId",
|
|
250
|
+
"groupDefaultExpanded",
|
|
251
|
+
"treeShowChildCount",
|
|
252
|
+
"treeIndentPx",
|
|
253
|
+
"treeToggleLabel",
|
|
254
|
+
"treeExpandAllControl",
|
|
255
|
+
"groupHideGroupedColumns",
|
|
256
|
+
"pinnedTopRowData",
|
|
257
|
+
"pinnedBottomRowData",
|
|
258
|
+
"pinnedBottomSummary",
|
|
259
|
+
"globalSearch",
|
|
260
|
+
"quickFilterText",
|
|
261
|
+
"columnChooser",
|
|
262
|
+
"csvExport",
|
|
263
|
+
"rowSelection",
|
|
264
|
+
"pagination",
|
|
265
|
+
"paginationPageSize",
|
|
266
|
+
"paginationPageSizeSelector",
|
|
267
|
+
"virtualization",
|
|
268
|
+
"responsivePinning",
|
|
269
|
+
"cellEditors",
|
|
270
|
+
"singleClickEdit",
|
|
271
|
+
"undoRedoCellEditing",
|
|
272
|
+
"undoRedoCellEditingLimit",
|
|
273
|
+
"initialState",
|
|
274
|
+
"initialSortModel",
|
|
275
|
+
"initialFilterModel",
|
|
276
|
+
"heightMode",
|
|
277
|
+
"maxHeight",
|
|
278
|
+
"stickyHeader",
|
|
279
|
+
"rowHeight",
|
|
280
|
+
"getRowHeight",
|
|
281
|
+
"getRowHref",
|
|
282
|
+
"asyncTransactionWaitMillis",
|
|
283
|
+
"headerHeight",
|
|
284
|
+
"theme",
|
|
285
|
+
"density",
|
|
286
|
+
"enableCellChangeFlash",
|
|
287
|
+
"ariaLabel",
|
|
288
|
+
"noRowsMessage",
|
|
289
|
+
"noMatchingRowsMessage",
|
|
290
|
+
"localeText",
|
|
291
|
+
"cellSelection",
|
|
292
|
+
"loading"
|
|
293
|
+
];
|
|
294
|
+
var StramienGrid = defineComponent({
|
|
295
|
+
name: "StramienGrid",
|
|
296
|
+
// class/style/id/data-* go to the host element (see the render function)
|
|
297
|
+
inheritAttrs: false,
|
|
298
|
+
props: {
|
|
299
|
+
rowData: { type: Array, default: () => [] },
|
|
300
|
+
columnDefs: { type: Array, default: () => [] },
|
|
301
|
+
defaultColDef: { type: Object, default: void 0 },
|
|
302
|
+
columnTypes: {
|
|
303
|
+
type: Object,
|
|
304
|
+
default: void 0
|
|
305
|
+
},
|
|
306
|
+
getRowId: {
|
|
307
|
+
type: Function,
|
|
308
|
+
default: void 0
|
|
309
|
+
},
|
|
310
|
+
rowModelType: { type: String, default: void 0 },
|
|
311
|
+
serverSideDatasource: {
|
|
312
|
+
type: Object,
|
|
313
|
+
default: void 0
|
|
314
|
+
},
|
|
315
|
+
masterDetail: { type: Boolean, default: void 0 },
|
|
316
|
+
isRowMaster: {
|
|
317
|
+
type: Function,
|
|
318
|
+
default: void 0
|
|
319
|
+
},
|
|
320
|
+
detailRowHeight: { type: Number, default: void 0 },
|
|
321
|
+
detailCellRenderer: {
|
|
322
|
+
type: [Function, Object, String],
|
|
323
|
+
default: void 0
|
|
324
|
+
},
|
|
325
|
+
expandOnRowClick: { type: Boolean, default: void 0 },
|
|
326
|
+
treeData: { type: Boolean, default: void 0 },
|
|
327
|
+
getDataPath: {
|
|
328
|
+
type: Function,
|
|
329
|
+
default: void 0
|
|
330
|
+
},
|
|
331
|
+
treeColumnId: { type: String, default: void 0 },
|
|
332
|
+
groupDefaultExpanded: { type: Number, default: void 0 },
|
|
333
|
+
treeShowChildCount: { type: Boolean, default: void 0 },
|
|
334
|
+
treeIndentPx: { type: Number, default: void 0 },
|
|
335
|
+
treeToggleLabel: {
|
|
336
|
+
type: Function,
|
|
337
|
+
default: void 0
|
|
338
|
+
},
|
|
339
|
+
treeExpandAllControl: {
|
|
340
|
+
type: [Boolean, String],
|
|
341
|
+
default: void 0
|
|
342
|
+
},
|
|
343
|
+
groupHideGroupedColumns: {
|
|
344
|
+
type: Boolean,
|
|
345
|
+
default: void 0
|
|
346
|
+
},
|
|
347
|
+
pinnedTopRowData: { type: Array, default: void 0 },
|
|
348
|
+
pinnedBottomRowData: { type: Array, default: void 0 },
|
|
349
|
+
pinnedBottomSummary: {
|
|
350
|
+
type: [Boolean, Object],
|
|
351
|
+
default: void 0
|
|
352
|
+
},
|
|
353
|
+
globalSearch: {
|
|
354
|
+
type: [Boolean, Object],
|
|
355
|
+
default: void 0
|
|
356
|
+
},
|
|
357
|
+
quickFilterText: { type: String, default: void 0 },
|
|
358
|
+
columnChooser: { type: Boolean, default: void 0 },
|
|
359
|
+
csvExport: {
|
|
360
|
+
type: [Boolean, Object],
|
|
361
|
+
default: void 0
|
|
362
|
+
},
|
|
363
|
+
rowSelection: {
|
|
364
|
+
type: [String, Object],
|
|
365
|
+
default: void 0
|
|
366
|
+
},
|
|
367
|
+
pagination: { type: Boolean, default: void 0 },
|
|
368
|
+
paginationPageSize: { type: Number, default: void 0 },
|
|
369
|
+
paginationPageSizeSelector: {
|
|
370
|
+
type: [Array, Boolean],
|
|
371
|
+
default: void 0
|
|
372
|
+
},
|
|
373
|
+
virtualization: {
|
|
374
|
+
type: [Boolean, Object],
|
|
375
|
+
default: void 0
|
|
376
|
+
},
|
|
377
|
+
responsivePinning: {
|
|
378
|
+
type: [Boolean, Object],
|
|
379
|
+
default: void 0
|
|
380
|
+
},
|
|
381
|
+
cellEditors: {
|
|
382
|
+
type: Object,
|
|
383
|
+
default: void 0
|
|
384
|
+
},
|
|
385
|
+
singleClickEdit: { type: Boolean, default: void 0 },
|
|
386
|
+
undoRedoCellEditing: { type: Boolean, default: void 0 },
|
|
387
|
+
undoRedoCellEditingLimit: { type: Number, default: void 0 },
|
|
388
|
+
initialState: { type: Object, default: void 0 },
|
|
389
|
+
initialSortModel: { type: Array, default: void 0 },
|
|
390
|
+
initialFilterModel: { type: Object, default: void 0 },
|
|
391
|
+
heightMode: {
|
|
392
|
+
type: String,
|
|
393
|
+
default: void 0
|
|
394
|
+
},
|
|
395
|
+
maxHeight: { type: String, default: void 0 },
|
|
396
|
+
stickyHeader: {
|
|
397
|
+
type: [Boolean, Object],
|
|
398
|
+
default: void 0
|
|
399
|
+
},
|
|
400
|
+
rowHeight: { type: Number, default: void 0 },
|
|
401
|
+
getRowHeight: {
|
|
402
|
+
type: Function,
|
|
403
|
+
default: void 0
|
|
404
|
+
},
|
|
405
|
+
getRowHref: {
|
|
406
|
+
type: Function,
|
|
407
|
+
default: void 0
|
|
408
|
+
},
|
|
409
|
+
asyncTransactionWaitMillis: { type: Number, default: void 0 },
|
|
410
|
+
headerHeight: { type: Number, default: void 0 },
|
|
411
|
+
theme: { type: String, default: void 0 },
|
|
412
|
+
density: { type: String, default: void 0 },
|
|
413
|
+
enableCellChangeFlash: { type: Boolean, default: void 0 },
|
|
414
|
+
ariaLabel: { type: String, default: void 0 },
|
|
415
|
+
noRowsMessage: { type: String, default: void 0 },
|
|
416
|
+
noMatchingRowsMessage: { type: String, default: void 0 },
|
|
417
|
+
localeText: { type: Object, default: void 0 },
|
|
418
|
+
cellSelection: {
|
|
419
|
+
type: [Boolean, Object],
|
|
420
|
+
default: void 0
|
|
421
|
+
},
|
|
422
|
+
loading: { type: Boolean, default: void 0 }
|
|
423
|
+
},
|
|
424
|
+
emits: {
|
|
425
|
+
gridReady: (_e) => true,
|
|
426
|
+
rowClicked: (_e) => true,
|
|
427
|
+
cellClicked: (_e) => true,
|
|
428
|
+
cellValueChanged: (_e) => true,
|
|
429
|
+
selectionChanged: (_e) => true,
|
|
430
|
+
sortChanged: (_e) => true,
|
|
431
|
+
filterChanged: (_e) => true,
|
|
432
|
+
columnResized: (_e) => true,
|
|
433
|
+
columnMoved: (_e) => true,
|
|
434
|
+
columnPinned: (_e) => true,
|
|
435
|
+
columnVisibilityChanged: (_e) => true,
|
|
436
|
+
paginationChanged: (_e) => true,
|
|
437
|
+
stateChanged: (_e) => true,
|
|
438
|
+
rowDetailToggled: (_e) => true,
|
|
439
|
+
treeNodeToggled: (_e) => true,
|
|
440
|
+
treeExpansionChanged: (_e) => true,
|
|
441
|
+
cellSelectionChanged: (_e) => true
|
|
442
|
+
},
|
|
443
|
+
setup(props, { emit, slots, expose, attrs }) {
|
|
444
|
+
const hostRef = ref(null);
|
|
445
|
+
let api = null;
|
|
446
|
+
let sentOptions = {};
|
|
447
|
+
let mounted = false;
|
|
448
|
+
const portalMap = /* @__PURE__ */ new Map();
|
|
449
|
+
let portalCounter = 0;
|
|
450
|
+
const portals = shallowRef([]);
|
|
451
|
+
let syncScheduled = false;
|
|
452
|
+
const schedulePortalSync = () => {
|
|
453
|
+
if (syncScheduled) return;
|
|
454
|
+
syncScheduled = true;
|
|
455
|
+
queueMicrotask(() => {
|
|
456
|
+
syncScheduled = false;
|
|
457
|
+
if (!mounted) return;
|
|
458
|
+
portals.value = [...portalMap.values()];
|
|
459
|
+
});
|
|
460
|
+
};
|
|
461
|
+
const mountPortal = (prefix, container, kind, params, slotName, renderer) => {
|
|
462
|
+
const id = `${prefix}-${++portalCounter}`;
|
|
463
|
+
const portalHost = document.createElement("div");
|
|
464
|
+
portalHost.className = "st-vue-cell";
|
|
465
|
+
portalHost.style.display = "contents";
|
|
466
|
+
container.appendChild(portalHost);
|
|
467
|
+
portalMap.set(id, { id, container: portalHost, kind, slotName, renderer, params });
|
|
468
|
+
schedulePortalSync();
|
|
469
|
+
return {
|
|
470
|
+
// New params for the same renderer (another field of the row changed): re-render
|
|
471
|
+
// with them, keeping the component instance and its state
|
|
472
|
+
update: (nextParams) => {
|
|
473
|
+
const entry = portalMap.get(id);
|
|
474
|
+
if (!entry) return;
|
|
475
|
+
portalMap.set(id, { ...entry, params: nextParams });
|
|
476
|
+
schedulePortalSync();
|
|
477
|
+
},
|
|
478
|
+
destroy: () => {
|
|
479
|
+
portalHost.remove();
|
|
480
|
+
if (portalMap.delete(id)) {
|
|
481
|
+
schedulePortalSync();
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
};
|
|
486
|
+
const mountAdapter = {
|
|
487
|
+
canMount: (renderer, colId) => {
|
|
488
|
+
if (typeof slots[`cell-${colId}`] === "function") return true;
|
|
489
|
+
return isVueRenderer(renderer);
|
|
490
|
+
},
|
|
491
|
+
mount: (container, renderer, params) => {
|
|
492
|
+
const slotName = `cell-${params.colDef.colId}`;
|
|
493
|
+
if (typeof slots[slotName] === "function") {
|
|
494
|
+
return mountPortal("st-vue-slot", container, "slot", params, slotName);
|
|
495
|
+
}
|
|
496
|
+
return mountPortal("st-vue-comp", container, "component", params, void 0, renderer);
|
|
497
|
+
},
|
|
498
|
+
// Custom editors: an #editor-<name> slot, or a Vue component from cellEditors /
|
|
499
|
+
// { component }
|
|
500
|
+
canMountEditor: (editor, name) => {
|
|
501
|
+
if (name && typeof slots[`editor-${name}`] === "function") return true;
|
|
502
|
+
return isVueRenderer(editor);
|
|
503
|
+
},
|
|
504
|
+
mountEditor: (container, editor, params) => {
|
|
505
|
+
const slotName = params.editorName ? `editor-${params.editorName}` : "";
|
|
506
|
+
if (slotName && typeof slots[slotName] === "function") {
|
|
507
|
+
return mountPortal("st-vue-editor-slot", container, "slot", params, slotName);
|
|
508
|
+
}
|
|
509
|
+
return mountPortal("st-vue-editor", container, "component", params, void 0, editor);
|
|
510
|
+
},
|
|
511
|
+
canMountDetail: (renderer) => {
|
|
512
|
+
if (typeof slots.detail === "function") return true;
|
|
513
|
+
return isVueRenderer(renderer);
|
|
514
|
+
},
|
|
515
|
+
mountDetail: (container, renderer, params) => {
|
|
516
|
+
if (typeof slots.detail === "function") {
|
|
517
|
+
return mountPortal("st-vue-detail-slot", container, "slot", params, "detail");
|
|
518
|
+
}
|
|
519
|
+
return mountPortal(
|
|
520
|
+
"st-vue-detail-comp",
|
|
521
|
+
container,
|
|
522
|
+
"component",
|
|
523
|
+
params,
|
|
524
|
+
void 0,
|
|
525
|
+
renderer
|
|
526
|
+
);
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
const getRowIdWrapper = (p) => props.getRowId ? props.getRowId(p) : String(p.index);
|
|
530
|
+
const isRowMasterWrapper = (data, node) => props.isRowMaster ? props.isRowMaster(data, node) : true;
|
|
531
|
+
const getDataPathWrapper = (data) => props.getDataPath ? props.getDataPath(data) : [];
|
|
532
|
+
const getRowHeightWrapper = (p) => props.getRowHeight?.(p);
|
|
533
|
+
const getRowHrefWrapper = (p) => props.getRowHref?.(p);
|
|
534
|
+
const callLatestDetail = (p) => props.detailCellRenderer(p);
|
|
535
|
+
const detailWrapper = (p) => callLatestDetail(p);
|
|
536
|
+
const detailWrapperVanilla = markVanillaRenderer(((p) => callLatestDetail(p)));
|
|
537
|
+
const detailOption = () => {
|
|
538
|
+
const detail = props.detailCellRenderer;
|
|
539
|
+
if (typeof detail !== "function") return detail;
|
|
540
|
+
return VANILLA_RENDERER_BRAND in detail ? detailWrapperVanilla : detailWrapper;
|
|
541
|
+
};
|
|
542
|
+
const rawRowData = createRawRowsMemo();
|
|
543
|
+
const rawPinnedTop = createRawRowsMemo();
|
|
544
|
+
const rawPinnedBottom = createRawRowsMemo();
|
|
545
|
+
const eventOptions = {
|
|
546
|
+
componentMountAdapter: mountAdapter,
|
|
547
|
+
onGridReady: (e) => {
|
|
548
|
+
api = e.api;
|
|
549
|
+
unwrapApiInputs(e.api);
|
|
550
|
+
emit("gridReady", e);
|
|
551
|
+
},
|
|
552
|
+
onRowClicked: (e) => emit("rowClicked", e),
|
|
553
|
+
onCellClicked: (e) => emit("cellClicked", e),
|
|
554
|
+
onCellValueChanged: (e) => emit("cellValueChanged", e),
|
|
555
|
+
onSelectionChanged: (e) => emit("selectionChanged", e),
|
|
556
|
+
onSortChanged: (e) => emit("sortChanged", e),
|
|
557
|
+
onFilterChanged: (e) => emit("filterChanged", e),
|
|
558
|
+
onColumnResized: (e) => emit("columnResized", e),
|
|
559
|
+
onColumnMoved: (e) => emit("columnMoved", e),
|
|
560
|
+
onColumnPinned: (e) => emit("columnPinned", e),
|
|
561
|
+
onColumnVisibilityChanged: (e) => emit("columnVisibilityChanged", e),
|
|
562
|
+
onPaginationChanged: (e) => emit("paginationChanged", e),
|
|
563
|
+
onStateChanged: (e) => emit("stateChanged", e),
|
|
564
|
+
onRowDetailToggled: (e) => emit("rowDetailToggled", e),
|
|
565
|
+
onTreeNodeToggled: (e) => emit("treeNodeToggled", e),
|
|
566
|
+
onTreeExpansionChanged: (e) => emit("treeExpansionChanged", e),
|
|
567
|
+
onCellSelectionChanged: (e) => emit("cellSelectionChanged", e)
|
|
568
|
+
};
|
|
569
|
+
const snapshotProps = () => {
|
|
570
|
+
const out = {};
|
|
571
|
+
for (const key of OPTION_KEYS) {
|
|
572
|
+
out[key] = props[key];
|
|
573
|
+
}
|
|
574
|
+
out.rowData = rawRowData(props.rowData);
|
|
575
|
+
out.pinnedTopRowData = rawPinnedTop(props.pinnedTopRowData);
|
|
576
|
+
out.pinnedBottomRowData = rawPinnedBottom(props.pinnedBottomRowData);
|
|
577
|
+
out.detailCellRenderer = detailOption();
|
|
578
|
+
out.getRowId = typeof props.getRowId === "function" ? getRowIdWrapper : void 0;
|
|
579
|
+
out.isRowMaster = typeof props.isRowMaster === "function" ? isRowMasterWrapper : void 0;
|
|
580
|
+
out.getDataPath = typeof props.getDataPath === "function" ? getDataPathWrapper : void 0;
|
|
581
|
+
out.getRowHeight = typeof props.getRowHeight === "function" ? getRowHeightWrapper : void 0;
|
|
582
|
+
out.getRowHref = typeof props.getRowHref === "function" ? getRowHrefWrapper : void 0;
|
|
583
|
+
return out;
|
|
584
|
+
};
|
|
585
|
+
onMounted(() => {
|
|
586
|
+
const el = hostRef.value;
|
|
587
|
+
if (!el) return;
|
|
588
|
+
mounted = true;
|
|
589
|
+
const initial = snapshotProps();
|
|
590
|
+
sentOptions = initial;
|
|
591
|
+
api = createGrid(el, {
|
|
592
|
+
...initial,
|
|
593
|
+
...eventOptions
|
|
594
|
+
});
|
|
595
|
+
});
|
|
596
|
+
watch(snapshotProps, (next) => {
|
|
597
|
+
if (!api) return;
|
|
598
|
+
const changed = {};
|
|
599
|
+
let hasChanges = false;
|
|
600
|
+
for (const key of Object.keys(next)) {
|
|
601
|
+
if (!Object.is(sentOptions[key], next[key])) {
|
|
602
|
+
changed[key] = next[key];
|
|
603
|
+
hasChanges = true;
|
|
604
|
+
}
|
|
605
|
+
}
|
|
606
|
+
sentOptions = next;
|
|
607
|
+
if (hasChanges) {
|
|
608
|
+
api.updateOptions(changed);
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
onBeforeUnmount(() => {
|
|
612
|
+
mounted = false;
|
|
613
|
+
api?.destroy();
|
|
614
|
+
api = null;
|
|
615
|
+
portalMap.clear();
|
|
616
|
+
portals.value = [];
|
|
617
|
+
});
|
|
618
|
+
expose({
|
|
619
|
+
getApi: () => api
|
|
620
|
+
});
|
|
621
|
+
return () => h(Fragment, null, [
|
|
622
|
+
h(
|
|
623
|
+
"div",
|
|
624
|
+
mergeProps(
|
|
625
|
+
{
|
|
626
|
+
ref: hostRef,
|
|
627
|
+
class: "st-grid-vue-host",
|
|
628
|
+
// Content height: the host follows the grid instead of filling its container
|
|
629
|
+
style: { width: "100%", height: props.heightMode === "content" ? "auto" : "100%" }
|
|
630
|
+
},
|
|
631
|
+
attrs
|
|
632
|
+
)
|
|
633
|
+
),
|
|
634
|
+
...portals.value.map(
|
|
635
|
+
(entry) => h(Teleport, { key: entry.id, to: entry.container }, [
|
|
636
|
+
h(CellErrorBoundary, {
|
|
637
|
+
slotFn: entry.slotName ? slots[entry.slotName] : void 0,
|
|
638
|
+
renderer: entry.renderer === detailWrapper ? props.detailCellRenderer : entry.renderer,
|
|
639
|
+
params: entry.params
|
|
640
|
+
})
|
|
641
|
+
])
|
|
642
|
+
)
|
|
643
|
+
]);
|
|
644
|
+
}
|
|
645
|
+
});
|
|
646
|
+
export {
|
|
647
|
+
DEFAULT_LOCALE_TEXT,
|
|
648
|
+
StramienGrid,
|
|
649
|
+
VANILLA_RENDERER_SYMBOL2 as VANILLA_RENDERER_SYMBOL,
|
|
650
|
+
actionsColumn,
|
|
651
|
+
badgeColumn,
|
|
652
|
+
barColumn,
|
|
653
|
+
booleanColumn,
|
|
654
|
+
createBuiltInColumnTypes,
|
|
655
|
+
currencyColumn,
|
|
656
|
+
formatLocaleText,
|
|
657
|
+
markVanillaRenderer2 as markVanillaRenderer,
|
|
658
|
+
percentColumn,
|
|
659
|
+
plural,
|
|
660
|
+
relativeTimeColumn,
|
|
661
|
+
sparklineColumn,
|
|
662
|
+
vanillaRenderer
|
|
663
|
+
};
|
|
664
|
+
//# sourceMappingURL=index.js.map
|