@nakashim/tp-custom 0.1.6
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 +68 -0
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +10 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/tp-plugin/counter-blade-plugin.d.ts +11 -0
- package/dist/lib/tp-plugin/counter-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/counter-blade-plugin.js +96 -0
- package/dist/lib/tp-plugin/counter-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/dynamic-list-blade-plugin.d.ts +159 -0
- package/dist/lib/tp-plugin/dynamic-list-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/dynamic-list-blade-plugin.js +719 -0
- package/dist/lib/tp-plugin/dynamic-list-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/image-container-blade-plugin.d.ts +67 -0
- package/dist/lib/tp-plugin/image-container-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/image-container-blade-plugin.js +251 -0
- package/dist/lib/tp-plugin/image-container-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/label-layout-utils.d.ts +2 -0
- package/dist/lib/tp-plugin/label-layout-utils.d.ts.map +1 -0
- package/dist/lib/tp-plugin/label-layout-utils.js +11 -0
- package/dist/lib/tp-plugin/label-layout-utils.js.map +1 -0
- package/dist/lib/tp-plugin/plain-blade-plugin.d.ts +28 -0
- package/dist/lib/tp-plugin/plain-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/plain-blade-plugin.js +86 -0
- package/dist/lib/tp-plugin/plain-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/register-custom-plugins.d.ts +4 -0
- package/dist/lib/tp-plugin/register-custom-plugins.d.ts.map +1 -0
- package/dist/lib/tp-plugin/register-custom-plugins.js +39 -0
- package/dist/lib/tp-plugin/register-custom-plugins.js.map +1 -0
- package/dist/lib/tp-plugin/row-blade-plugin.d.ts +48 -0
- package/dist/lib/tp-plugin/row-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/row-blade-plugin.js +216 -0
- package/dist/lib/tp-plugin/row-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/text-blade-plugin.d.ts +80 -0
- package/dist/lib/tp-plugin/text-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/text-blade-plugin.js +276 -0
- package/dist/lib/tp-plugin/text-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/text-input-blade-plugin.d.ts +81 -0
- package/dist/lib/tp-plugin/text-input-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/text-input-blade-plugin.js +385 -0
- package/dist/lib/tp-plugin/text-input-blade-plugin.js.map +1 -0
- package/dist/lib/tp-plugin/toggle-blade-plugin.d.ts +64 -0
- package/dist/lib/tp-plugin/toggle-blade-plugin.d.ts.map +1 -0
- package/dist/lib/tp-plugin/toggle-blade-plugin.js +343 -0
- package/dist/lib/tp-plugin/toggle-blade-plugin.js.map +1 -0
- package/dist/styles/assets/fonts/JetBrainsMono-VariableFont_wght.ttf +0 -0
- package/dist/styles/assets/icons/check-16.svg +1 -0
- package/dist/styles/assets/icons/chevron-down-12.svg +1 -0
- package/dist/styles/assets/icons/chevron-up-12.svg +1 -0
- package/dist/styles/assets/icons/triangle-down-16.svg +1 -0
- package/dist/styles/assets/icons/x-12.svg +1 -0
- package/dist/styles/assets/images/bg-grid.png +0 -0
- package/dist/styles/tp-custom.css +329 -0
- package/package.json +54 -0
|
@@ -0,0 +1,719 @@
|
|
|
1
|
+
import { BladeApi, BladeController, createPlugin, parseRecord } from '@tweakpane/core';
|
|
2
|
+
function sanitizeListStyle(style) {
|
|
3
|
+
return style === 'ul' ? 'ul' : 'ol';
|
|
4
|
+
}
|
|
5
|
+
function normalizeMaxItems(value) {
|
|
6
|
+
if (!Number.isFinite(value)) {
|
|
7
|
+
return undefined;
|
|
8
|
+
}
|
|
9
|
+
const normalized = Math.floor(value);
|
|
10
|
+
if (normalized < 1) {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
return normalized;
|
|
14
|
+
}
|
|
15
|
+
function sanitizeOverflowMode(mode) {
|
|
16
|
+
return mode === 'reject' ? 'reject' : 'drop-oldest';
|
|
17
|
+
}
|
|
18
|
+
function clampItemsToMax(items, maxItems, keepNewest = true) {
|
|
19
|
+
if (!Number.isFinite(maxItems)) {
|
|
20
|
+
return items;
|
|
21
|
+
}
|
|
22
|
+
const max = maxItems;
|
|
23
|
+
if (items.length <= max) {
|
|
24
|
+
return items;
|
|
25
|
+
}
|
|
26
|
+
return keepNewest ? items.slice(items.length - max) : items.slice(0, max);
|
|
27
|
+
}
|
|
28
|
+
function normalizeRows(value) {
|
|
29
|
+
if (!Number.isFinite(value)) {
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
const normalized = Math.floor(value);
|
|
33
|
+
if (normalized < 1) {
|
|
34
|
+
return undefined;
|
|
35
|
+
}
|
|
36
|
+
return Math.min(24, normalized);
|
|
37
|
+
}
|
|
38
|
+
class DynamicListBladeView {
|
|
39
|
+
element;
|
|
40
|
+
labelElement_;
|
|
41
|
+
listContainer_;
|
|
42
|
+
listElement_;
|
|
43
|
+
onListClick_;
|
|
44
|
+
itemRows_;
|
|
45
|
+
emptyItemElement_;
|
|
46
|
+
items_;
|
|
47
|
+
listStyle_;
|
|
48
|
+
rows_;
|
|
49
|
+
onMoveUp_;
|
|
50
|
+
onMoveDown_;
|
|
51
|
+
onRemove_;
|
|
52
|
+
allowRemove_;
|
|
53
|
+
allowReorder_;
|
|
54
|
+
inlineLabel_;
|
|
55
|
+
showItemTooltip_;
|
|
56
|
+
fullWidth_;
|
|
57
|
+
constructor(doc, config) {
|
|
58
|
+
this.items_ = [...config.items];
|
|
59
|
+
this.listStyle_ = config.listStyle;
|
|
60
|
+
this.onMoveUp_ = config.onMoveUp;
|
|
61
|
+
this.onMoveDown_ = config.onMoveDown;
|
|
62
|
+
this.onRemove_ = config.onRemove;
|
|
63
|
+
this.allowRemove_ = config.allowRemove;
|
|
64
|
+
this.allowReorder_ = config.allowReorder;
|
|
65
|
+
this.inlineLabel_ = config.inlineLabel;
|
|
66
|
+
this.showItemTooltip_ = config.showItemTooltip;
|
|
67
|
+
this.fullWidth_ = config.fullWidth;
|
|
68
|
+
this.rows_ = normalizeRows(config.rows);
|
|
69
|
+
this.itemRows_ = [];
|
|
70
|
+
this.emptyItemElement_ = null;
|
|
71
|
+
this.onListClick_ = (ev) => {
|
|
72
|
+
const target = ev.target;
|
|
73
|
+
if (!target)
|
|
74
|
+
return;
|
|
75
|
+
const button = target.closest('.tp-dynlistblade_btn');
|
|
76
|
+
if (!button || button.disabled)
|
|
77
|
+
return;
|
|
78
|
+
const item = button.closest('.tp-dynlistblade_i');
|
|
79
|
+
if (!item)
|
|
80
|
+
return;
|
|
81
|
+
const index = Number(item.dataset.index);
|
|
82
|
+
if (!Number.isInteger(index))
|
|
83
|
+
return;
|
|
84
|
+
const action = button.dataset.action;
|
|
85
|
+
if (action === 'up') {
|
|
86
|
+
this.onMoveUp_(index);
|
|
87
|
+
}
|
|
88
|
+
else if (action === 'down') {
|
|
89
|
+
this.onMoveDown_(index);
|
|
90
|
+
}
|
|
91
|
+
else if (action === 'remove') {
|
|
92
|
+
this.onRemove_(index);
|
|
93
|
+
}
|
|
94
|
+
};
|
|
95
|
+
const root = doc.createElement('div');
|
|
96
|
+
root.className = 'tp-dynlistblade';
|
|
97
|
+
root.classList.toggle('tp-dynlistblade-inline', this.inlineLabel_);
|
|
98
|
+
root.classList.toggle('tp-dynlistblade-full', this.fullWidth_);
|
|
99
|
+
const label = doc.createElement('div');
|
|
100
|
+
label.className = 'tp-dynlistblade_l';
|
|
101
|
+
label.textContent = config.label ?? 'Dynamic List';
|
|
102
|
+
root.appendChild(label);
|
|
103
|
+
this.labelElement_ = label;
|
|
104
|
+
const container = doc.createElement('div');
|
|
105
|
+
container.className = 'tp-dynlistblade_c';
|
|
106
|
+
root.appendChild(container);
|
|
107
|
+
this.listContainer_ = container;
|
|
108
|
+
this.listElement_ = this.createListElement_(doc, this.listStyle_);
|
|
109
|
+
this.listContainer_.appendChild(this.listElement_);
|
|
110
|
+
this.element = root;
|
|
111
|
+
this.applyRows_();
|
|
112
|
+
this.render_();
|
|
113
|
+
}
|
|
114
|
+
get items() {
|
|
115
|
+
return [...this.items_];
|
|
116
|
+
}
|
|
117
|
+
set items(next) {
|
|
118
|
+
this.items_ = [...next];
|
|
119
|
+
this.render_();
|
|
120
|
+
}
|
|
121
|
+
setOptions(next) {
|
|
122
|
+
if (typeof next.allowRemove === 'boolean') {
|
|
123
|
+
this.allowRemove_ = next.allowRemove;
|
|
124
|
+
}
|
|
125
|
+
if (typeof next.allowReorder === 'boolean') {
|
|
126
|
+
this.allowReorder_ = next.allowReorder;
|
|
127
|
+
}
|
|
128
|
+
if (typeof next.showItemTooltip === 'boolean') {
|
|
129
|
+
this.showItemTooltip_ = next.showItemTooltip;
|
|
130
|
+
}
|
|
131
|
+
this.render_();
|
|
132
|
+
}
|
|
133
|
+
set inlineLabel(next) {
|
|
134
|
+
this.inlineLabel_ = Boolean(next);
|
|
135
|
+
this.element.classList.toggle('tp-dynlistblade-inline', this.inlineLabel_);
|
|
136
|
+
}
|
|
137
|
+
set fullWidth(next) {
|
|
138
|
+
this.fullWidth_ = Boolean(next);
|
|
139
|
+
this.element.classList.toggle('tp-dynlistblade-full', this.fullWidth_);
|
|
140
|
+
}
|
|
141
|
+
get rows() {
|
|
142
|
+
return this.rows_;
|
|
143
|
+
}
|
|
144
|
+
set rows(next) {
|
|
145
|
+
this.rows_ = normalizeRows(next);
|
|
146
|
+
this.applyRows_();
|
|
147
|
+
}
|
|
148
|
+
set label(next) {
|
|
149
|
+
this.labelElement_.textContent = next;
|
|
150
|
+
}
|
|
151
|
+
get listStyle() {
|
|
152
|
+
return this.listStyle_;
|
|
153
|
+
}
|
|
154
|
+
set listStyle(next) {
|
|
155
|
+
const normalized = sanitizeListStyle(next);
|
|
156
|
+
if (normalized === this.listStyle_) {
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
this.listStyle_ = normalized;
|
|
160
|
+
const doc = this.element.ownerDocument;
|
|
161
|
+
const newList = this.createListElement_(doc, normalized);
|
|
162
|
+
this.listContainer_.replaceChild(newList, this.listElement_);
|
|
163
|
+
this.listElement_ = newList;
|
|
164
|
+
this.render_();
|
|
165
|
+
}
|
|
166
|
+
createListElement_(doc, style) {
|
|
167
|
+
const list = doc.createElement(style);
|
|
168
|
+
list.className = `tp-dynlistblade_list tp-dynlistblade_list-${style}`;
|
|
169
|
+
list.addEventListener('click', this.onListClick_);
|
|
170
|
+
return list;
|
|
171
|
+
}
|
|
172
|
+
applyRows_() {
|
|
173
|
+
if (!Number.isFinite(this.rows_)) {
|
|
174
|
+
this.element.classList.remove('tp-dynlistblade-has-rows');
|
|
175
|
+
this.element.style.removeProperty('--tp-dynlistblade-rows');
|
|
176
|
+
this.element.style.removeProperty('--tp-dynlistblade-rows-gap');
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const rows = this.rows_;
|
|
180
|
+
this.element.classList.add('tp-dynlistblade-has-rows');
|
|
181
|
+
this.element.style.setProperty('--tp-dynlistblade-rows', String(rows));
|
|
182
|
+
this.element.style.setProperty('--tp-dynlistblade-rows-gap', String(Math.max(0, rows - 1)));
|
|
183
|
+
}
|
|
184
|
+
render_() {
|
|
185
|
+
if (this.items_.length === 0) {
|
|
186
|
+
this.ensureEmptyState_();
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
this.clearEmptyState_();
|
|
190
|
+
this.ensureRowCount_(this.items_.length);
|
|
191
|
+
this.items_.forEach((text, index) => {
|
|
192
|
+
const row = this.itemRows_[index];
|
|
193
|
+
row.item.dataset.index = String(index);
|
|
194
|
+
row.text.textContent = text;
|
|
195
|
+
if (this.showItemTooltip_) {
|
|
196
|
+
row.text.title = text;
|
|
197
|
+
}
|
|
198
|
+
else {
|
|
199
|
+
row.text.removeAttribute('title');
|
|
200
|
+
}
|
|
201
|
+
const showActions = this.allowRemove_ || this.allowReorder_;
|
|
202
|
+
row.actions.style.display = showActions ? '' : 'none';
|
|
203
|
+
row.upButton.style.display = this.allowReorder_ ? '' : 'none';
|
|
204
|
+
row.downButton.style.display = this.allowReorder_ ? '' : 'none';
|
|
205
|
+
row.removeButton.style.display = this.allowRemove_ ? '' : 'none';
|
|
206
|
+
row.upButton.disabled = !this.allowReorder_ || index === 0;
|
|
207
|
+
row.downButton.disabled = !this.allowReorder_ || index === this.items_.length - 1;
|
|
208
|
+
row.removeButton.disabled = !this.allowRemove_;
|
|
209
|
+
this.listElement_.appendChild(row.item);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
ensureEmptyState_() {
|
|
213
|
+
if (!this.emptyItemElement_) {
|
|
214
|
+
const emptyItem = this.element.ownerDocument.createElement('li');
|
|
215
|
+
emptyItem.className = 'tp-dynlistblade_i tp-dynlistblade_i-empty';
|
|
216
|
+
const emptyRow = this.element.ownerDocument.createElement('div');
|
|
217
|
+
emptyRow.className = 'tp-dynlistblade_row tp-dynlistblade_row-empty';
|
|
218
|
+
emptyItem.appendChild(emptyRow);
|
|
219
|
+
const emptyText = this.element.ownerDocument.createElement('span');
|
|
220
|
+
emptyText.className = 'tp-dynlistblade_t tp-dynlistblade_t-empty';
|
|
221
|
+
emptyText.textContent = 'Empty';
|
|
222
|
+
emptyRow.appendChild(emptyText);
|
|
223
|
+
this.emptyItemElement_ = emptyItem;
|
|
224
|
+
}
|
|
225
|
+
this.itemRows_.forEach((row) => {
|
|
226
|
+
if (row.item.parentElement === this.listElement_) {
|
|
227
|
+
this.listElement_.removeChild(row.item);
|
|
228
|
+
}
|
|
229
|
+
});
|
|
230
|
+
if (this.emptyItemElement_.parentElement !== this.listElement_) {
|
|
231
|
+
this.listElement_.appendChild(this.emptyItemElement_);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
clearEmptyState_() {
|
|
235
|
+
if (this.emptyItemElement_ && this.emptyItemElement_.parentElement === this.listElement_) {
|
|
236
|
+
this.listElement_.removeChild(this.emptyItemElement_);
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
ensureRowCount_(count) {
|
|
240
|
+
while (this.itemRows_.length < count) {
|
|
241
|
+
this.itemRows_.push(this.createItemRow_());
|
|
242
|
+
}
|
|
243
|
+
while (this.itemRows_.length > count) {
|
|
244
|
+
const removed = this.itemRows_.pop();
|
|
245
|
+
if (!removed)
|
|
246
|
+
break;
|
|
247
|
+
if (removed.item.parentElement === this.listElement_) {
|
|
248
|
+
this.listElement_.removeChild(removed.item);
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
createItemRow_() {
|
|
253
|
+
const item = this.element.ownerDocument.createElement('li');
|
|
254
|
+
item.className = 'tp-dynlistblade_i';
|
|
255
|
+
const row = this.element.ownerDocument.createElement('div');
|
|
256
|
+
row.className = 'tp-dynlistblade_row';
|
|
257
|
+
item.appendChild(row);
|
|
258
|
+
const text = this.element.ownerDocument.createElement('span');
|
|
259
|
+
text.className = 'tp-dynlistblade_t';
|
|
260
|
+
row.appendChild(text);
|
|
261
|
+
const actions = this.element.ownerDocument.createElement('span');
|
|
262
|
+
actions.className = 'tp-dynlistblade_a';
|
|
263
|
+
row.appendChild(actions);
|
|
264
|
+
const upButton = this.createActionButton_('▴', 'Move up', 'up');
|
|
265
|
+
const downButton = this.createActionButton_('▾', 'Move down', 'down');
|
|
266
|
+
const removeButton = this.createActionButton_('×', 'Remove', 'remove');
|
|
267
|
+
actions.appendChild(upButton);
|
|
268
|
+
actions.appendChild(downButton);
|
|
269
|
+
actions.appendChild(removeButton);
|
|
270
|
+
return { item, text, actions, upButton, downButton, removeButton };
|
|
271
|
+
}
|
|
272
|
+
createActionButton_(text, title, action) {
|
|
273
|
+
const button = this.element.ownerDocument.createElement('button');
|
|
274
|
+
button.type = 'button';
|
|
275
|
+
button.className = `tp-dynlistblade_btn tp-dynlistblade_btn-${action}`;
|
|
276
|
+
button.dataset.action = action;
|
|
277
|
+
button.textContent = text;
|
|
278
|
+
button.title = title;
|
|
279
|
+
return button;
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
class DynamicListBladeController extends BladeController {
|
|
283
|
+
items_;
|
|
284
|
+
rows_;
|
|
285
|
+
maxItems_;
|
|
286
|
+
overflowMode_;
|
|
287
|
+
allowRemove_;
|
|
288
|
+
allowReorder_;
|
|
289
|
+
inlineLabel_;
|
|
290
|
+
showItemTooltip_;
|
|
291
|
+
fullWidth_;
|
|
292
|
+
constructor(doc, config) {
|
|
293
|
+
const initialItems = clampItemsToMax([...config.items], config.maxItems, true);
|
|
294
|
+
const view = new DynamicListBladeView(doc, {
|
|
295
|
+
label: config.label,
|
|
296
|
+
listStyle: config.listStyle,
|
|
297
|
+
items: initialItems,
|
|
298
|
+
rows: normalizeRows(config.rows),
|
|
299
|
+
onMoveUp: (index) => this.moveUp(index),
|
|
300
|
+
onMoveDown: (index) => this.moveDown(index),
|
|
301
|
+
onRemove: (index) => this.remove(index),
|
|
302
|
+
allowRemove: config.allowRemove,
|
|
303
|
+
allowReorder: config.allowReorder,
|
|
304
|
+
inlineLabel: config.inlineLabel,
|
|
305
|
+
showItemTooltip: config.showItemTooltip,
|
|
306
|
+
fullWidth: config.fullWidth,
|
|
307
|
+
});
|
|
308
|
+
super({
|
|
309
|
+
blade: config.blade,
|
|
310
|
+
view,
|
|
311
|
+
viewProps: config.viewProps,
|
|
312
|
+
});
|
|
313
|
+
this.items_ = initialItems;
|
|
314
|
+
this.rows_ = normalizeRows(config.rows);
|
|
315
|
+
this.maxItems_ = normalizeMaxItems(config.maxItems);
|
|
316
|
+
this.overflowMode_ = sanitizeOverflowMode(config.overflowMode);
|
|
317
|
+
this.allowRemove_ = config.allowRemove;
|
|
318
|
+
this.allowReorder_ = config.allowReorder;
|
|
319
|
+
this.inlineLabel_ = config.inlineLabel;
|
|
320
|
+
this.showItemTooltip_ = config.showItemTooltip;
|
|
321
|
+
this.fullWidth_ = config.fullWidth;
|
|
322
|
+
}
|
|
323
|
+
get items() {
|
|
324
|
+
return [...this.items_];
|
|
325
|
+
}
|
|
326
|
+
get rows() {
|
|
327
|
+
return this.rows_;
|
|
328
|
+
}
|
|
329
|
+
set rows(next) {
|
|
330
|
+
this.rows_ = normalizeRows(next);
|
|
331
|
+
this.view.rows = this.rows_;
|
|
332
|
+
}
|
|
333
|
+
set items(next) {
|
|
334
|
+
this.items_ = clampItemsToMax([...next], this.maxItems_, true);
|
|
335
|
+
this.view.items = this.items_;
|
|
336
|
+
}
|
|
337
|
+
get maxItems() {
|
|
338
|
+
return this.maxItems_;
|
|
339
|
+
}
|
|
340
|
+
set maxItems(next) {
|
|
341
|
+
this.maxItems_ = normalizeMaxItems(next);
|
|
342
|
+
this.items_ = clampItemsToMax(this.items_, this.maxItems_, true);
|
|
343
|
+
this.view.items = this.items_;
|
|
344
|
+
}
|
|
345
|
+
get overflowMode() {
|
|
346
|
+
return this.overflowMode_;
|
|
347
|
+
}
|
|
348
|
+
set overflowMode(next) {
|
|
349
|
+
this.overflowMode_ = sanitizeOverflowMode(next);
|
|
350
|
+
}
|
|
351
|
+
get allowRemove() {
|
|
352
|
+
return this.allowRemove_;
|
|
353
|
+
}
|
|
354
|
+
set allowRemove(next) {
|
|
355
|
+
this.allowRemove_ = Boolean(next);
|
|
356
|
+
this.view.setOptions({ allowRemove: this.allowRemove_ });
|
|
357
|
+
}
|
|
358
|
+
get allowReorder() {
|
|
359
|
+
return this.allowReorder_;
|
|
360
|
+
}
|
|
361
|
+
set allowReorder(next) {
|
|
362
|
+
this.allowReorder_ = Boolean(next);
|
|
363
|
+
this.view.setOptions({ allowReorder: this.allowReorder_ });
|
|
364
|
+
}
|
|
365
|
+
get showItemTooltip() {
|
|
366
|
+
return this.showItemTooltip_;
|
|
367
|
+
}
|
|
368
|
+
set showItemTooltip(next) {
|
|
369
|
+
this.showItemTooltip_ = Boolean(next);
|
|
370
|
+
this.view.setOptions({ showItemTooltip: this.showItemTooltip_ });
|
|
371
|
+
}
|
|
372
|
+
get inlineLabel() {
|
|
373
|
+
return this.inlineLabel_;
|
|
374
|
+
}
|
|
375
|
+
set inlineLabel(next) {
|
|
376
|
+
this.inlineLabel_ = Boolean(next);
|
|
377
|
+
this.view.inlineLabel = this.inlineLabel_;
|
|
378
|
+
}
|
|
379
|
+
get fullWidth() {
|
|
380
|
+
return this.fullWidth_;
|
|
381
|
+
}
|
|
382
|
+
set fullWidth(next) {
|
|
383
|
+
this.fullWidth_ = Boolean(next);
|
|
384
|
+
this.view.fullWidth = this.fullWidth_;
|
|
385
|
+
}
|
|
386
|
+
get listStyle() {
|
|
387
|
+
return this.view.listStyle;
|
|
388
|
+
}
|
|
389
|
+
set listStyle(next) {
|
|
390
|
+
this.view.listStyle = next;
|
|
391
|
+
}
|
|
392
|
+
setLabel(next) {
|
|
393
|
+
this.view.label = next;
|
|
394
|
+
}
|
|
395
|
+
add(item) {
|
|
396
|
+
if (Number.isFinite(this.maxItems_)) {
|
|
397
|
+
const max = this.maxItems_;
|
|
398
|
+
if (this.items_.length >= max) {
|
|
399
|
+
if (this.overflowMode_ === 'reject') {
|
|
400
|
+
return false;
|
|
401
|
+
}
|
|
402
|
+
this.items_.shift();
|
|
403
|
+
}
|
|
404
|
+
}
|
|
405
|
+
this.items_.push(item);
|
|
406
|
+
this.view.items = this.items_;
|
|
407
|
+
return true;
|
|
408
|
+
}
|
|
409
|
+
remove(index) {
|
|
410
|
+
if (index < 0 || index >= this.items_.length)
|
|
411
|
+
return;
|
|
412
|
+
this.items_.splice(index, 1);
|
|
413
|
+
this.view.items = this.items_;
|
|
414
|
+
}
|
|
415
|
+
moveUp(index) {
|
|
416
|
+
if (index <= 0 || index >= this.items_.length)
|
|
417
|
+
return;
|
|
418
|
+
const tmp = this.items_[index - 1];
|
|
419
|
+
this.items_[index - 1] = this.items_[index];
|
|
420
|
+
this.items_[index] = tmp;
|
|
421
|
+
this.view.items = this.items_;
|
|
422
|
+
}
|
|
423
|
+
moveDown(index) {
|
|
424
|
+
if (index < 0 || index >= this.items_.length - 1)
|
|
425
|
+
return;
|
|
426
|
+
const tmp = this.items_[index + 1];
|
|
427
|
+
this.items_[index + 1] = this.items_[index];
|
|
428
|
+
this.items_[index] = tmp;
|
|
429
|
+
this.view.items = this.items_;
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
export class DynamicListBladeApi extends BladeApi {
|
|
433
|
+
get items() {
|
|
434
|
+
return this.controller.items;
|
|
435
|
+
}
|
|
436
|
+
get rows() {
|
|
437
|
+
return this.controller.rows;
|
|
438
|
+
}
|
|
439
|
+
set rows(next) {
|
|
440
|
+
this.controller.rows = next;
|
|
441
|
+
}
|
|
442
|
+
set items(next) {
|
|
443
|
+
this.controller.items = next.map((v) => String(v));
|
|
444
|
+
}
|
|
445
|
+
get maxItems() {
|
|
446
|
+
return this.controller.maxItems;
|
|
447
|
+
}
|
|
448
|
+
set maxItems(next) {
|
|
449
|
+
this.controller.maxItems = next;
|
|
450
|
+
}
|
|
451
|
+
get overflowMode() {
|
|
452
|
+
return this.controller.overflowMode;
|
|
453
|
+
}
|
|
454
|
+
set overflowMode(next) {
|
|
455
|
+
this.controller.overflowMode = sanitizeOverflowMode(next);
|
|
456
|
+
}
|
|
457
|
+
get allowRemove() {
|
|
458
|
+
return this.controller.allowRemove;
|
|
459
|
+
}
|
|
460
|
+
set allowRemove(next) {
|
|
461
|
+
this.controller.allowRemove = Boolean(next);
|
|
462
|
+
}
|
|
463
|
+
get allowReorder() {
|
|
464
|
+
return this.controller.allowReorder;
|
|
465
|
+
}
|
|
466
|
+
set allowReorder(next) {
|
|
467
|
+
this.controller.allowReorder = Boolean(next);
|
|
468
|
+
}
|
|
469
|
+
get inlineLabel() {
|
|
470
|
+
return this.controller.inlineLabel;
|
|
471
|
+
}
|
|
472
|
+
set inlineLabel(next) {
|
|
473
|
+
this.controller.inlineLabel = Boolean(next);
|
|
474
|
+
}
|
|
475
|
+
get showItemTooltip() {
|
|
476
|
+
return this.controller.showItemTooltip;
|
|
477
|
+
}
|
|
478
|
+
set showItemTooltip(next) {
|
|
479
|
+
this.controller.showItemTooltip = Boolean(next);
|
|
480
|
+
}
|
|
481
|
+
get fullWidth() {
|
|
482
|
+
return this.controller.fullWidth;
|
|
483
|
+
}
|
|
484
|
+
set fullWidth(next) {
|
|
485
|
+
this.controller.fullWidth = Boolean(next);
|
|
486
|
+
}
|
|
487
|
+
get listStyle() {
|
|
488
|
+
return this.controller.listStyle;
|
|
489
|
+
}
|
|
490
|
+
set listStyle(next) {
|
|
491
|
+
this.controller.listStyle = sanitizeListStyle(next);
|
|
492
|
+
}
|
|
493
|
+
setLabel(next) {
|
|
494
|
+
this.controller.setLabel(String(next));
|
|
495
|
+
}
|
|
496
|
+
addItem(text) {
|
|
497
|
+
return this.controller.add(String(text));
|
|
498
|
+
}
|
|
499
|
+
removeItem(index) {
|
|
500
|
+
this.controller.remove(index);
|
|
501
|
+
}
|
|
502
|
+
moveUp(index) {
|
|
503
|
+
this.controller.moveUp(index);
|
|
504
|
+
}
|
|
505
|
+
moveDown(index) {
|
|
506
|
+
this.controller.moveDown(index);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
const DynamicListBladePlugin = createPlugin({
|
|
510
|
+
id: 'dynamiclistblade',
|
|
511
|
+
type: 'blade',
|
|
512
|
+
accept(params) {
|
|
513
|
+
const result = parseRecord(params, (p) => ({
|
|
514
|
+
view: p.required.constant('dynamiclistblade'),
|
|
515
|
+
label: p.optional.string,
|
|
516
|
+
listStyle: p.optional.custom((value) => value === 'ul' || value === 'ol' ? value : undefined),
|
|
517
|
+
items: p.optional.array(p.required.string),
|
|
518
|
+
rows: p.optional.number,
|
|
519
|
+
maxItems: p.optional.number,
|
|
520
|
+
overflowMode: p.optional.custom((value) => value === 'reject' || value === 'drop-oldest' ? value : undefined),
|
|
521
|
+
allowRemove: p.optional.boolean,
|
|
522
|
+
allowReorder: p.optional.boolean,
|
|
523
|
+
inlineLabel: p.optional.boolean,
|
|
524
|
+
showItemTooltip: p.optional.boolean,
|
|
525
|
+
fullWidth: p.optional.boolean,
|
|
526
|
+
}));
|
|
527
|
+
if (!result) {
|
|
528
|
+
return null;
|
|
529
|
+
}
|
|
530
|
+
return {
|
|
531
|
+
params: {
|
|
532
|
+
...result,
|
|
533
|
+
listStyle: sanitizeListStyle(result.listStyle),
|
|
534
|
+
items: result.items ?? [],
|
|
535
|
+
rows: normalizeRows(result.rows),
|
|
536
|
+
maxItems: normalizeMaxItems(result.maxItems),
|
|
537
|
+
overflowMode: sanitizeOverflowMode(result.overflowMode),
|
|
538
|
+
allowRemove: result.allowRemove ?? true,
|
|
539
|
+
allowReorder: result.allowReorder ?? true,
|
|
540
|
+
inlineLabel: result.inlineLabel ?? false,
|
|
541
|
+
showItemTooltip: result.showItemTooltip ?? false,
|
|
542
|
+
fullWidth: result.fullWidth ?? false,
|
|
543
|
+
},
|
|
544
|
+
};
|
|
545
|
+
},
|
|
546
|
+
controller(args) {
|
|
547
|
+
return new DynamicListBladeController(args.document, {
|
|
548
|
+
blade: args.blade,
|
|
549
|
+
viewProps: args.viewProps,
|
|
550
|
+
label: args.params.label,
|
|
551
|
+
listStyle: sanitizeListStyle(args.params.listStyle),
|
|
552
|
+
items: args.params.items ?? [],
|
|
553
|
+
rows: normalizeRows(args.params.rows),
|
|
554
|
+
maxItems: normalizeMaxItems(args.params.maxItems),
|
|
555
|
+
overflowMode: sanitizeOverflowMode(args.params.overflowMode),
|
|
556
|
+
allowRemove: args.params.allowRemove ?? true,
|
|
557
|
+
allowReorder: args.params.allowReorder ?? true,
|
|
558
|
+
inlineLabel: args.params.inlineLabel ?? false,
|
|
559
|
+
showItemTooltip: args.params.showItemTooltip ?? false,
|
|
560
|
+
fullWidth: args.params.fullWidth ?? false,
|
|
561
|
+
});
|
|
562
|
+
},
|
|
563
|
+
api(args) {
|
|
564
|
+
if (!(args.controller instanceof DynamicListBladeController)) {
|
|
565
|
+
return null;
|
|
566
|
+
}
|
|
567
|
+
return new DynamicListBladeApi(args.controller);
|
|
568
|
+
},
|
|
569
|
+
});
|
|
570
|
+
export const DynamicListBladePluginBundle = {
|
|
571
|
+
id: 'dynamiclistblade-bundle',
|
|
572
|
+
plugins: [DynamicListBladePlugin],
|
|
573
|
+
css: `
|
|
574
|
+
.tp-dynlistblade {
|
|
575
|
+
padding-inline: var(--tp-c-container-padding-inline);
|
|
576
|
+
}
|
|
577
|
+
.tp-dynlistblade.tp-dynlistblade-inline {
|
|
578
|
+
display: flex;
|
|
579
|
+
align-items: center;
|
|
580
|
+
padding-inline: var(--tp-c-container-padding-inline);
|
|
581
|
+
}
|
|
582
|
+
.tp-dynlistblade.tp-dynlistblade-inline .tp-dynlistblade_l {
|
|
583
|
+
flex: 1;
|
|
584
|
+
flex-basis: var(--tp-c-base-label-flex-basis);
|
|
585
|
+
padding-inline: 0 var(--tp-c-container-padding-inline);
|
|
586
|
+
}
|
|
587
|
+
.tp-dynlistblade.tp-dynlistblade-inline .tp-dynlistblade_c {
|
|
588
|
+
flex-basis: var(--tp-c-base-value-flex-basis);
|
|
589
|
+
align-self: flex-start;
|
|
590
|
+
flex-grow: 0;
|
|
591
|
+
flex-shrink: 0;
|
|
592
|
+
width: auto;
|
|
593
|
+
}
|
|
594
|
+
.tp-dynlistblade.tp-dynlistblade-inline .tp-dynlistblade_list {
|
|
595
|
+
margin: 0;
|
|
596
|
+
}
|
|
597
|
+
.tp-dynlistblade.tp-dynlistblade-full .tp-dynlistblade_list {
|
|
598
|
+
margin: 0;
|
|
599
|
+
}
|
|
600
|
+
.tp-dynlistblade.tp-dynlistblade-full .tp-dynlistblade_l {
|
|
601
|
+
display: none;
|
|
602
|
+
}
|
|
603
|
+
.tp-dynlistblade_l {
|
|
604
|
+
color: var(--tp-label-foreground-color);
|
|
605
|
+
padding-block: var(--tp-c-textarea-padding-block);
|
|
606
|
+
}
|
|
607
|
+
.tp-dynlistblade_list {
|
|
608
|
+
border-radius: var(--tp-c-base-border-radius);
|
|
609
|
+
background: var(--tp-monitor-background-color);
|
|
610
|
+
margin: var(--tp-c-container-vertical-gap) 0 0;
|
|
611
|
+
padding-inline: var(--tp-c-container-padding-inline);
|
|
612
|
+
padding-block: var(--tp-c-textarea-padding-block);
|
|
613
|
+
display: flex;
|
|
614
|
+
flex-direction: column;
|
|
615
|
+
list-style: none;
|
|
616
|
+
}
|
|
617
|
+
.tp-dynlistblade.tp-dynlistblade-has-rows .tp-dynlistblade_list {
|
|
618
|
+
height: calc(
|
|
619
|
+
14px * var(--tp-dynlistblade-rows, 6) +
|
|
620
|
+
3px * var(--tp-dynlistblade-rows-gap, 5)
|
|
621
|
+
);
|
|
622
|
+
overflow: auto;
|
|
623
|
+
}
|
|
624
|
+
.tp-dynlistblade_list::-webkit-scrollbar {
|
|
625
|
+
width: 10px;
|
|
626
|
+
}
|
|
627
|
+
.tp-dynlistblade_list::-webkit-scrollbar-track {
|
|
628
|
+
background: transparent;
|
|
629
|
+
border-radius: 999px;
|
|
630
|
+
}
|
|
631
|
+
.tp-dynlistblade_list::-webkit-scrollbar-thumb {
|
|
632
|
+
background: rgba(255, 255, 255, 0.2);
|
|
633
|
+
border-radius: 999px;
|
|
634
|
+
border: 2px solid transparent;
|
|
635
|
+
background-clip: padding-box;
|
|
636
|
+
}
|
|
637
|
+
.tp-dynlistblade_list {
|
|
638
|
+
scrollbar-width: thin;
|
|
639
|
+
scrollbar-color: rgba(255, 255, 255, 0.2) transparent;
|
|
640
|
+
}
|
|
641
|
+
.tp-dynlistblade_i {
|
|
642
|
+
min-width: 0;
|
|
643
|
+
}
|
|
644
|
+
.tp-dynlistblade_i::after {
|
|
645
|
+
content: '';
|
|
646
|
+
display: block;
|
|
647
|
+
width: 100%;
|
|
648
|
+
height: 1px;
|
|
649
|
+
border-radius: 0.5px;
|
|
650
|
+
background: rgba(255, 255, 255, 0.03);
|
|
651
|
+
margin-block: 1px;
|
|
652
|
+
}
|
|
653
|
+
.tp-dynlistblade_i:last-child::after {
|
|
654
|
+
display: none;
|
|
655
|
+
}
|
|
656
|
+
.tp-dynlistblade_row {
|
|
657
|
+
display: inline-flex;
|
|
658
|
+
align-items: center;
|
|
659
|
+
vertical-align: top;
|
|
660
|
+
width: 100%;
|
|
661
|
+
}
|
|
662
|
+
.tp-dynlistblade_row::before {
|
|
663
|
+
content: '';
|
|
664
|
+
font-size: 10px;
|
|
665
|
+
color: rgba(255, 255, 255, 0.2);
|
|
666
|
+
display: inline-block;
|
|
667
|
+
min-width: 10px;
|
|
668
|
+
margin-right: 4px;
|
|
669
|
+
}
|
|
670
|
+
.tp-dynlistblade_list-ol .tp-dynlistblade_row::before {
|
|
671
|
+
content: counter(list-item) '';
|
|
672
|
+
}
|
|
673
|
+
.tp-dynlistblade_list-ul .tp-dynlistblade_row::before {
|
|
674
|
+
content: '-';
|
|
675
|
+
}
|
|
676
|
+
.tp-dynlistblade_t {
|
|
677
|
+
width: 100%;
|
|
678
|
+
flex: 1;
|
|
679
|
+
color: var(--tp-input-foreground-color);
|
|
680
|
+
white-space: nowrap;
|
|
681
|
+
overflow: hidden;
|
|
682
|
+
text-overflow: ellipsis;
|
|
683
|
+
}
|
|
684
|
+
.tp-dynlistblade_list-ol .tp-dynlistblade_row-empty::before {
|
|
685
|
+
content: '0';
|
|
686
|
+
}
|
|
687
|
+
.tp-dynlistblade_t-empty {
|
|
688
|
+
color: rgba(255, 255, 255, 0.2);
|
|
689
|
+
}
|
|
690
|
+
.tp-dynlistblade_a {
|
|
691
|
+
display: inline-flex;
|
|
692
|
+
align-items: center;
|
|
693
|
+
gap: 2px;
|
|
694
|
+
overflow: hidden;
|
|
695
|
+
}
|
|
696
|
+
.tp-dynlistblade_btn {
|
|
697
|
+
appearance: none;
|
|
698
|
+
border: none;
|
|
699
|
+
background: transparent;
|
|
700
|
+
color: var(--tp-label-foreground-color);
|
|
701
|
+
width: 14px;
|
|
702
|
+
height: 14px;
|
|
703
|
+
border-radius: var(--tp-c-base-border-radius);
|
|
704
|
+
cursor: pointer;
|
|
705
|
+
padding: 0;
|
|
706
|
+
line-height: 1;
|
|
707
|
+
font-size: 13px;
|
|
708
|
+
}
|
|
709
|
+
.tp-dynlistblade_btn:hover {
|
|
710
|
+
background: var(--tp-input-background-color-hover);
|
|
711
|
+
color: var(--tp-input-foreground-color);
|
|
712
|
+
}
|
|
713
|
+
.tp-dynlistblade_btn:disabled {
|
|
714
|
+
opacity: 0.3;
|
|
715
|
+
cursor: default;
|
|
716
|
+
}
|
|
717
|
+
`,
|
|
718
|
+
};
|
|
719
|
+
//# sourceMappingURL=dynamic-list-blade-plugin.js.map
|