@swiftwc/ui 0.0.0-dev.87 → 0.0.0-dev.88

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.
@@ -1,54 +1,95 @@
1
1
  import { I18n } from '../../i18n';
2
- import { default as $ } from './cash';
3
- function renderPlaceholder(el, role, titleKey, config) {
4
- // if (!el.isConnected) return
5
- // self.requestAnimationFrame(() => {
6
- // if (!el.isConnected) return
7
- const label = el.querySelector(':scope>[slot=placeholder]') ?? el.appendChild($(`<label-view slot="placeholder"></label-view>`, '>1'));
2
+ import { html, queryMorph } from '../../morphdom';
3
+ // type ButtonRole = keyof ReturnType<typeof I18n.t<'ButtonRole'>>
4
+ // function renderPlaceholder(el: HTMLElement, role: string | null, titleKey?: ButtonRole, config?: Record<string, string>) {
5
+ // // if (!el.isConnected) return
6
+ // // self.requestAnimationFrame(() => {
7
+ // // if (!el.isConnected) return
8
+ // let title: string | undefined, systemImage: string | undefined
9
+ // // const label = el.querySelector(':scope>[slot=placeholder]') ?? el.appendChild($(`<label-view slot="placeholder"></label-view>`, '>1'))
10
+ // switch (role) {
11
+ // case 'cancel':
12
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel //label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel)
13
+ // systemImage = config?.['cancel-button-icon'] ?? '' //label.setAttribute('system-image', config?.['cancel-button-icon'] ?? '')
14
+ // break
15
+ // case 'close':
16
+ // if (el.closest('[is=alert-dialog]')) {
17
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').OK //.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').OK)
18
+ // } else {
19
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Close //label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Close)
20
+ // systemImage = config?.['close-button-icon'] ?? '' //label.setAttribute('system-image', config?.['close-button-icon'] ?? '')
21
+ // }
22
+ // break
23
+ // case 'confirm':
24
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm //label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm)
25
+ // systemImage = config?.['confirm-button-icon'] ?? '' //label.setAttribute('system-image', config?.['confirm-button-icon'] ?? '')
26
+ // break
27
+ // case 'confirmation-action':
28
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm //label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm)
29
+ // systemImage = config?.['confirm-button-icon'] ?? '' //label.setAttribute('system-image', config?.['confirm-button-icon'] ?? '')
30
+ // break
31
+ // case 'cancellation-action':
32
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel //label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel)
33
+ // systemImage = config?.['cancel-button-icon'] ?? '' //label.setAttribute('system-image', config?.['cancel-button-icon'] ?? '')
34
+ // break
35
+ // case 'destructive':
36
+ // title = titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Destructive // label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Destructive)
37
+ // systemImage = config?.['delete-button-icon'] ?? '' // label.setAttribute('system-image', config?.['delete-button-icon'] ?? '')
38
+ // break
39
+ // // default:
40
+ // // label?.remove()
41
+ // // break
42
+ // }
43
+ // queryMorph(
44
+ // '[slot=placeholder]',
45
+ // html`<label-view slot="placeholder">${systemImage ? html`<image-view slot="icon" system-name="${systemImage}"></image-view>` : null}${title ? html`<span>${title}</span>` : null}</label-view>`,
46
+ // el,
47
+ // { removeIf: !title }
48
+ // )
49
+ // // if (role) {
50
+ // // label.setAttribute('title', I18n.t('ButtonRole').Default.Destructive)
51
+ // // } else label?.remove()
52
+ // // })
53
+ // }
54
+ export default function (target, role, titleKey, config) {
55
+ if (!target)
56
+ return;
57
+ const overiderTitle = typeof titleKey === 'string' && titleKey in I18n.t('ButtonRole') ? titleKey : undefined;
58
+ // renderPlaceholder(target, role, overiderTitle, config)
59
+ let title, systemImage;
60
+ // const label = el.querySelector(':scope>[slot=placeholder]') ?? el.appendChild($(`<label-view slot="placeholder"></label-view>`, '>1'))
8
61
  switch (role) {
9
62
  case 'cancel':
10
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel);
11
- label.setAttribute('system-image', config['cancel-button-icon']);
63
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Cancel;
64
+ systemImage = config?.['cancel-button-icon'] ?? '';
12
65
  break;
13
66
  case 'close':
14
- if (label.closest('[is=alert-dialog]')) {
15
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').OK);
67
+ if (target.closest('[is=alert-dialog]')) {
68
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').OK;
16
69
  }
17
70
  else {
18
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Close);
19
- label.setAttribute('system-image', config['close-button-icon']);
71
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Close;
72
+ systemImage = config?.['close-button-icon'] ?? '';
20
73
  }
21
74
  break;
22
75
  case 'confirm':
23
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm);
24
- label.setAttribute('system-image', config['confirm-button-icon']);
76
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Confirm;
77
+ systemImage = config?.['confirm-button-icon'] ?? '';
25
78
  break;
26
79
  case 'confirmation-action':
27
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Confirm);
28
- label.setAttribute('system-image', config['confirm-button-icon']);
80
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Confirm;
81
+ systemImage = config?.['confirm-button-icon'] ?? '';
29
82
  break;
30
83
  case 'cancellation-action':
31
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Cancel);
32
- label.setAttribute('system-image', config['cancel-button-icon']);
84
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Cancel;
85
+ systemImage = config?.['cancel-button-icon'] ?? '';
33
86
  break;
34
87
  case 'destructive':
35
- label.setAttribute('title', titleKey && titleKey in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[titleKey] : I18n.t('ButtonRole').Destructive);
36
- label.setAttribute('system-image', config['delete-button-icon']);
37
- break;
38
- default:
39
- label?.remove();
88
+ title = overiderTitle && overiderTitle in I18n.t('ButtonRole') ? I18n.t('ButtonRole')[overiderTitle] : I18n.t('ButtonRole').Destructive;
89
+ systemImage = config?.['delete-button-icon'] ?? '';
40
90
  break;
41
91
  }
42
- // if (role) {
43
- // label.setAttribute('title', I18n.t('ButtonRole').Default.Destructive)
44
- // } else label?.remove()
45
- // })
46
- }
47
- export default function (target, role, titleKey, config) {
48
- if (!target)
49
- return;
50
- const overiderTitle = typeof titleKey === 'string' && titleKey in I18n.t('ButtonRole') ? titleKey : undefined;
51
- renderPlaceholder(target, role, overiderTitle);
92
+ queryMorph('[slot=placeholder]', html `<label-view slot="placeholder">${systemImage ? html `<image-view slot="icon" system-name="${systemImage}"></image-view>` : null}${title ? html `<span>${title}</span>` : null}</label-view>`, target, { removeIf: !title });
52
93
  // CleanupRegistry.unregister(target, 'i18n')
53
94
  // CleanupRegistry.register(target, onoff('localechange', () => renderPlaceholder(target, role, overiderTitle), I18n.on).on(), 'i18n')
54
95
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@swiftwc/ui",
3
- "version": "0.0.0-dev.87",
3
+ "version": "0.0.0-dev.88",
4
4
  "description": "Elegant SwiftUI-inspired web components for standalone web apps and web extensions.",
5
5
  "publishConfig": {
6
6
  "access": "public"