@kubex/zinc 1.1.80 → 1.1.82
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/dist/custom-elements.json +339 -50
- package/dist/vscode.html-custom-data.json +34 -4
- package/dist/web-types.json +97 -7
- package/dist/zn.d.ts +374 -294
- package/dist/zn.min.js +311 -288
- package/docs/pages/components/inline-edit.md +3 -2
- package/docs/pages/components/input.md +21 -0
- package/docs/pages/components/remarkd-editor.md +43 -0
- package/docs/pages/components/slash-menu.md +7 -14
- package/docs/pages/components/translations.md +25 -7
- package/package.json +1 -1
- package/src/components/inline-edit/inline-edit.component.ts +7 -2
- package/src/components/input/input.component.ts +143 -0
- package/src/components/input/input.test.ts +113 -1
- package/src/components/remarkd-editor/remarkd-editor.component.ts +157 -95
- package/src/components/remarkd-editor/remarkd-editor.scss +24 -36
- package/src/components/remarkd-editor/remarkd-editor.test.ts +110 -6
- package/src/components/slash-menu/slash-menu.component.ts +23 -1
- package/src/components/translations/translations.component.ts +17 -2
- package/src/components/translations/translations.test.ts +42 -0
|
@@ -188,7 +188,24 @@ export default class ZnSlashMenu extends ZincElement {
|
|
|
188
188
|
|
|
189
189
|
private scrollActiveIntoView() {
|
|
190
190
|
const active = this.renderRoot.querySelector<HTMLElement>('[data-slash-item][aria-selected="true"]');
|
|
191
|
-
active
|
|
191
|
+
if (!active) return;
|
|
192
|
+
|
|
193
|
+
const items = this.visibleItems;
|
|
194
|
+
const panel = this.panel;
|
|
195
|
+
|
|
196
|
+
// The heading and footer scroll with the list, and `nearest` stops at the item's own box — so
|
|
197
|
+
// landing on the first or last item goes all the way to the panel's edge to bring them back
|
|
198
|
+
if (panel && items.slice(0, this.activeIndex).every(item => item.disabled)) {
|
|
199
|
+
panel.scrollTop = 0;
|
|
200
|
+
return;
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
if (panel && items.slice(this.activeIndex + 1).every(item => item.disabled)) {
|
|
204
|
+
panel.scrollTop = panel.scrollHeight;
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
active.scrollIntoView({block: 'nearest'});
|
|
192
209
|
}
|
|
193
210
|
|
|
194
211
|
// mousedown, not click: preventDefault keeps focus (and the caret) in the field
|
|
@@ -216,6 +233,11 @@ export default class ZnSlashMenu extends ZincElement {
|
|
|
216
233
|
protected updated(changed: PropertyValues) {
|
|
217
234
|
super.updated(changed);
|
|
218
235
|
|
|
236
|
+
// A new list, or a reopen, starts at the top rather than wherever the last one was scrolled to
|
|
237
|
+
if (changed.has('items') || (changed.has('open') && this.open)) {
|
|
238
|
+
this.scrollActiveIntoView();
|
|
239
|
+
}
|
|
240
|
+
|
|
219
241
|
if (changed.has('open') || changed.has('anchor')) {
|
|
220
242
|
if (this.open) {
|
|
221
243
|
this.startPositioner();
|
|
@@ -33,11 +33,17 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
|
|
|
33
33
|
};
|
|
34
34
|
|
|
35
35
|
private readonly formControlController: FormControlController = new FormControlController(this);
|
|
36
|
-
private readonly hasSlotController = new HasSlotController(this, 'label', 'expand');
|
|
36
|
+
private readonly hasSlotController = new HasSlotController(this, 'label', 'expand', 'help-text');
|
|
37
37
|
|
|
38
38
|
@property() name = '';
|
|
39
39
|
@property() value = '{"en":""}';
|
|
40
40
|
@property() label: string = '';
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Text shown below the field, describing how to fill it in. Applies to every language. If you need HTML, use the
|
|
44
|
+
* `help-text` slot instead.
|
|
45
|
+
*/
|
|
46
|
+
@property({attribute: 'help-text'}) helpText: string = '';
|
|
41
47
|
@property({type: Boolean, reflect: true}) disabled = false;
|
|
42
48
|
@property({type: Boolean, reflect: true}) required = false;
|
|
43
49
|
@property({type: Boolean, reflect: true}) flush = false;
|
|
@@ -45,7 +51,7 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
|
|
|
45
51
|
@property({attribute: "textarea-rows", type: Number}) textareaRows: number | undefined;
|
|
46
52
|
|
|
47
53
|
/**
|
|
48
|
-
* Quick insertions offered by the slash menu
|
|
54
|
+
* Quick insertions offered by the slash menu on `text` and `textarea` inputs. Accepts a JSON array of items, or
|
|
49
55
|
* the shorthand `Brand name={{BRAND_NAME}}, Support email={{SUPPORT_EMAIL}}`. Every language shares the list.
|
|
50
56
|
*/
|
|
51
57
|
@property({
|
|
@@ -356,6 +362,8 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
|
|
|
356
362
|
const hasLabelSlot = this.hasSlotController.test('label');
|
|
357
363
|
const hasLabel = this.label ? true : hasLabelSlot;
|
|
358
364
|
const hasExpandSlot = this.hasSlotController.test('expand');
|
|
365
|
+
const hasHelpTextSlot = this.hasSlotController.test('help-text');
|
|
366
|
+
const hasHelpText = this.helpText ? true : hasHelpTextSlot;
|
|
359
367
|
const hasMultipleLanguages = Object.keys(this.languages).length > 1;
|
|
360
368
|
const showActions = !this.grouped && (hasMultipleLanguages || hasExpandSlot);
|
|
361
369
|
|
|
@@ -368,6 +376,7 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
|
|
|
368
376
|
'form-control': true,
|
|
369
377
|
'form-control--medium': true,
|
|
370
378
|
'form-control--has-label': hasLabel,
|
|
379
|
+
'form-control--has-help-text': hasHelpText,
|
|
371
380
|
})}"
|
|
372
381
|
@keydown="${this.handleKeyDown}">
|
|
373
382
|
<div class="translations__header">
|
|
@@ -443,6 +452,12 @@ export default class ZnTranslations extends ZincElement implements ZincFormContr
|
|
|
443
452
|
></zn-inline-edit>
|
|
444
453
|
`)}
|
|
445
454
|
</div>
|
|
455
|
+
|
|
456
|
+
${hasHelpText ? html`
|
|
457
|
+
<div part="form-control-help-text" class="form-control__help-text" aria-hidden="false">
|
|
458
|
+
<slot name="help-text">${this.helpText}</slot>
|
|
459
|
+
</div>
|
|
460
|
+
` : nothing}
|
|
446
461
|
</div>
|
|
447
462
|
`;
|
|
448
463
|
}
|
|
@@ -50,6 +50,48 @@ describe('<zn-translations>', () => {
|
|
|
50
50
|
await expect(JSON.parse(el.value)).to.deep.equal({'en': 'Hello World'});
|
|
51
51
|
});
|
|
52
52
|
|
|
53
|
+
describe('help text', () => {
|
|
54
|
+
function helpTextOf(el: ZnTranslations) {
|
|
55
|
+
return el.shadowRoot!.querySelector<HTMLElement>('[part="form-control-help-text"]');
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
it('is not rendered when unset', async () => {
|
|
59
|
+
const el = await fixture<ZnTranslations>(html`<zn-translations></zn-translations>`);
|
|
60
|
+
await el.updateComplete;
|
|
61
|
+
|
|
62
|
+
expect(helpTextOf(el)).to.not.exist;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
it('renders the help-text attribute below the field', async () => {
|
|
66
|
+
const el = await fixture<ZnTranslations>(html`
|
|
67
|
+
<zn-translations help-text="Type / to insert a replacement"></zn-translations>`);
|
|
68
|
+
await el.updateComplete;
|
|
69
|
+
|
|
70
|
+
expect(helpTextOf(el)?.textContent?.trim()).to.equal('Type / to insert a replacement');
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it('renders the help-text slot', async () => {
|
|
74
|
+
const el = await fixture<ZnTranslations>(html`
|
|
75
|
+
<zn-translations>
|
|
76
|
+
<div slot="help-text">Type <strong>/</strong> to insert</div>
|
|
77
|
+
</zn-translations>`);
|
|
78
|
+
await el.updateComplete;
|
|
79
|
+
|
|
80
|
+
expect(helpTextOf(el), 'a slotted help text should still render the wrapper').to.exist;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('shows the same help text after switching language', async () => {
|
|
84
|
+
const el = await fixture<ZnTranslations>(html`
|
|
85
|
+
<zn-translations help-text="Type / to insert a replacement"></zn-translations>`);
|
|
86
|
+
el.languages = {'en': 'EN', 'fr': 'FR'};
|
|
87
|
+
el.values = {'en': '', 'fr': ''};
|
|
88
|
+
el.setActiveLanguage('fr');
|
|
89
|
+
await el.updateComplete;
|
|
90
|
+
|
|
91
|
+
expect(helpTextOf(el)?.textContent?.trim()).to.equal('Type / to insert a replacement');
|
|
92
|
+
});
|
|
93
|
+
});
|
|
94
|
+
|
|
53
95
|
describe('slash menu', () => {
|
|
54
96
|
/** Puts the active language's field into edit mode, the way clicking it does. */
|
|
55
97
|
async function textareaOf(el: ZnTranslations) {
|