@windwalker-io/unicorn-next 0.1.4 → 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.
Files changed (129) hide show
  1. package/.editorconfig +18 -18
  2. package/.gulp.json +7 -7
  3. package/bin/release.mjs +47 -47
  4. package/dist/chunks/button-radio.js.map +1 -1
  5. package/dist/chunks/checkboxes-multi-select.js.map +1 -1
  6. package/dist/chunks/field-cascade-select.js.map +1 -1
  7. package/dist/chunks/field-file-drag.js.map +1 -1
  8. package/dist/chunks/field-flatpickr.js.map +1 -1
  9. package/dist/chunks/field-modal-select.js.map +1 -1
  10. package/dist/chunks/field-modal-tree.js +2 -2
  11. package/dist/chunks/field-modal-tree.js.map +1 -1
  12. package/dist/chunks/field-multi-uploader.js.map +1 -1
  13. package/dist/chunks/field-repeatable.js.map +1 -1
  14. package/dist/chunks/field-single-image-drag.js.map +1 -1
  15. package/dist/chunks/form.js.map +1 -1
  16. package/dist/chunks/grid.js.map +1 -1
  17. package/dist/chunks/http-client.js.map +1 -1
  18. package/dist/chunks/iframe-modal.js.map +1 -1
  19. package/dist/chunks/keep-tab.js.map +1 -1
  20. package/dist/chunks/legacy.js +2 -2
  21. package/dist/chunks/legacy.js.map +1 -1
  22. package/dist/chunks/list-dependent.js.map +1 -1
  23. package/dist/chunks/s3-multipart-uploader.js.map +1 -1
  24. package/dist/chunks/s3-uploader.js.map +1 -1
  25. package/dist/chunks/show-on.js.map +1 -1
  26. package/dist/chunks/tinymce.js +1 -1
  27. package/dist/chunks/tinymce.js.map +1 -1
  28. package/dist/chunks/ui-bootstrap5.js.map +1 -1
  29. package/dist/chunks/unicorn.js +22 -16
  30. package/dist/chunks/unicorn.js.map +1 -1
  31. package/dist/chunks/validation.js +1 -1
  32. package/dist/chunks/validation.js.map +1 -1
  33. package/dist/index.d.ts +39 -30
  34. package/dist/unicorn.js +11 -9
  35. package/fusionfile.mjs +155 -155
  36. package/package.json +103 -103
  37. package/scss/bootstrap/multi-level-menu.scss +121 -121
  38. package/scss/editor.scss +116 -116
  39. package/scss/field/file-drag.scss +102 -102
  40. package/scss/field/single-image-drag.scss +88 -88
  41. package/scss/field/vue-drag-uploader.scss +160 -160
  42. package/scss/switcher.scss +156 -156
  43. package/src/app.ts +128 -128
  44. package/src/bootstrap/button-radio.ts +208 -208
  45. package/src/bootstrap/keep-tab.ts +155 -155
  46. package/src/composable/index.ts +22 -21
  47. package/src/composable/useCheckboxesMultiSelect.ts +22 -22
  48. package/src/composable/useFieldCascadeSelect.ts +9 -9
  49. package/src/composable/useFieldFileDrag.ts +9 -9
  50. package/src/composable/useFieldFlatpickr.ts +3 -3
  51. package/src/composable/useFieldModalSelect.ts +6 -6
  52. package/src/composable/useFieldModalTree.ts +3 -3
  53. package/src/composable/useFieldMultiUploader.ts +9 -9
  54. package/src/composable/useFieldRepeatable.ts +9 -9
  55. package/src/composable/useFieldSingleImageDrag.ts +9 -9
  56. package/src/composable/useForm.ts +43 -43
  57. package/src/composable/useGrid.ts +57 -57
  58. package/src/composable/useHttp.ts +9 -9
  59. package/src/composable/useIframeModal.ts +10 -10
  60. package/src/composable/useListDependent.ts +26 -26
  61. package/src/composable/useQueue.ts +13 -13
  62. package/src/composable/useS3Uploader.ts +32 -32
  63. package/src/composable/useShowOn.ts +9 -9
  64. package/src/composable/useStack.ts +13 -13
  65. package/src/composable/useTinymce.ts +29 -29
  66. package/src/composable/useTomSelect.ts +72 -72
  67. package/src/composable/useUIBootstrap5.ts +48 -48
  68. package/src/composable/useUniDirective.ts +32 -32
  69. package/src/composable/useValidation.ts +50 -39
  70. package/src/data.ts +34 -34
  71. package/src/events.ts +82 -82
  72. package/src/legacy/legacy.ts +190 -190
  73. package/src/legacy/loader.ts +125 -125
  74. package/src/module/checkboxes-multi-select.ts +54 -54
  75. package/src/module/field-cascade-select.ts +292 -292
  76. package/src/module/field-file-drag.ts +295 -295
  77. package/src/module/field-flatpickr.ts +130 -130
  78. package/src/module/field-modal-select.ts +179 -179
  79. package/src/module/field-modal-tree.ts +31 -31
  80. package/src/module/field-multi-uploader.ts +368 -368
  81. package/src/module/field-repeatable.ts +202 -202
  82. package/src/module/field-single-image-drag.ts +475 -475
  83. package/src/module/form.ts +223 -223
  84. package/src/module/grid.ts +465 -465
  85. package/src/module/http-client.ts +248 -248
  86. package/src/module/iframe-modal.ts +170 -170
  87. package/src/module/list-dependent.ts +321 -321
  88. package/src/module/s3-multipart-uploader.ts +300 -300
  89. package/src/module/s3-uploader.ts +234 -234
  90. package/src/module/show-on.ts +175 -175
  91. package/src/module/tinymce.ts +276 -276
  92. package/src/module/ui-bootstrap5.ts +116 -116
  93. package/src/module/validation.ts +1046 -1026
  94. package/src/plugin/index.ts +1 -1
  95. package/src/plugin/php-adapter.ts +72 -72
  96. package/src/polyfill/form-request-submit.ts +31 -31
  97. package/src/polyfill/index.ts +9 -9
  98. package/src/service/animate.ts +58 -58
  99. package/src/service/crypto.ts +27 -27
  100. package/src/service/dom-watcher.ts +62 -62
  101. package/src/service/dom.ts +265 -265
  102. package/src/service/helper.ts +48 -48
  103. package/src/service/index.ts +10 -10
  104. package/src/service/lang.ts +122 -122
  105. package/src/service/loader.ts +152 -152
  106. package/src/service/router.ts +118 -118
  107. package/src/service/ui.ts +525 -525
  108. package/src/service/uri.ts +106 -106
  109. package/src/types/base.ts +9 -9
  110. package/src/types/index.ts +4 -4
  111. package/src/types/modal-tree.ts +12 -12
  112. package/src/types/plugin.ts +6 -6
  113. package/src/types/shims.d.ts +18 -18
  114. package/src/types/ui.ts +6 -6
  115. package/src/unicorn.ts +79 -79
  116. package/src/utilities/arr.ts +25 -25
  117. package/src/utilities/base.ts +9 -9
  118. package/src/utilities/data.ts +48 -48
  119. package/src/utilities/index.ts +5 -5
  120. package/src/utilities/tree.ts +20 -20
  121. package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -175
  122. package/src/vue/components/ModalTree/TreeItem.vue +262 -262
  123. package/src/vue/components/ModalTree/TreeModal.vue +225 -225
  124. package/tests/test.js +4 -4
  125. package/tsconfig.js.json +25 -25
  126. package/tsconfig.json +17 -17
  127. package/vite.assets.config.ts +61 -61
  128. package/vite.config.test.ts +36 -36
  129. package/vite.config.ts +112 -112
@@ -1,130 +1,130 @@
1
- import { useCssImport, useImport, injectCssToDocument } from '../service';
2
- import flatpickr from 'flatpickr';
3
- import css from 'flatpickr/dist/flatpickr.css?inline';
4
-
5
- export class FlatpickrElement extends HTMLElement {
6
- static get is() {
7
- return 'uni-flatpickr';
8
- }
9
-
10
- instance!: flatpickr.Instance;
11
-
12
- constructor() {
13
- super();
14
- }
15
-
16
- get selector() {
17
- return this.getAttribute('selector') || 'input';
18
- }
19
-
20
- get locale() {
21
- return this.getAttribute('locale') || '';
22
- }
23
-
24
- // todo: Currently not support single option attributes
25
- getOptions() {
26
- const options: any = {};
27
- const ignore = [
28
- 'selector'
29
- ];
30
-
31
- this.getAttributeNames().forEach((name) => {
32
- if (ignore.indexOf(name) !== -1) {
33
- return;
34
- }
35
-
36
- options[name] = this.getAttribute(name);
37
- });
38
-
39
- return options;
40
- }
41
-
42
- get $input(): HTMLInputElement {
43
- return this.querySelector<HTMLInputElement>('input')!;
44
- }
45
-
46
- async connectedCallback() {
47
- let options: flatpickr.Options.Options = JSON.parse(this.getAttribute('options') || '{}') || {};
48
-
49
- options.autoFillDefaultTime = true;
50
- const now = new Date();
51
- options.defaultHour = now.getHours();
52
- options.defaultMinute = now.getMinutes();
53
- options.defaultSeconds = now.getSeconds();
54
-
55
- options = await this.handleOptions(options);
56
-
57
- this.instance = flatpickr(
58
- this.querySelector<HTMLElement>(this.selector)!,
59
- options
60
- );
61
-
62
- // If no value, set default time on open
63
- this.instance.config.onOpen.push(() => {
64
- if (this.instance.input.value === '') {
65
- const now = new Date();
66
- this.instance.jumpToDate(now);
67
- this.instance.config.defaultHour = now.getHours();
68
- this.instance.config.defaultMinute = now.getMinutes();
69
- this.instance.config.defaultSeconds = now.getSeconds();
70
- }
71
- });
72
-
73
- this.querySelector('[data-toggle]')?.addEventListener('click', () => {
74
- setTimeout(() => {
75
- this.querySelector<HTMLInputElement>('[data-input]')?.focus();
76
- }, 0);
77
- });
78
- }
79
-
80
- async handleOptions(options: flatpickr.Options.Options): Promise<flatpickr.Options.Options> {
81
- options.plugins = options.plugins || [];
82
-
83
- await Promise.all([
84
- this.handleLocale(options),
85
- this.handleMonthSelect(options)
86
- ]);
87
-
88
- return options;
89
- }
90
-
91
- private async handleLocale(options: Record<string, any>) {
92
- if (this.locale) {
93
- await useImport(`@flatpickr/l10n/${this.locale}.js`);
94
-
95
- options.locale = this.locale.replace(/-/, '_');
96
- }
97
-
98
- return options;
99
- }
100
-
101
- private async handleMonthSelect(options: Record<string, any>) {
102
- if (options.monthSelect) {
103
- useCssImport('flatpickr/dist/plugins/monthSelect/style.css');
104
- const { default: monthSelect } = await import('flatpickr/dist/plugins/monthSelect');
105
-
106
- if (typeof options.monthSelect === 'boolean') {
107
- options.monthSelect = {
108
- shorthand: true,
109
- dateFormat: 'Y-m',
110
- altFormat: 'Y-m'
111
- };
112
- }
113
-
114
- options.plugins.push(monthSelect(options.monthSelect));
115
- }
116
-
117
- return options;
118
- }
119
-
120
- getInstance() {
121
- return this.instance;
122
- }
123
- }
124
-
125
- async function init() {
126
- injectCssToDocument(css);
127
- customElements.define(FlatpickrElement.is, FlatpickrElement);
128
- }
129
-
130
- export const ready = init();
1
+ import { useCssImport, useImport, injectCssToDocument } from '../service';
2
+ import flatpickr from 'flatpickr';
3
+ import css from 'flatpickr/dist/flatpickr.css?inline';
4
+
5
+ export class FlatpickrElement extends HTMLElement {
6
+ static get is() {
7
+ return 'uni-flatpickr';
8
+ }
9
+
10
+ instance!: flatpickr.Instance;
11
+
12
+ constructor() {
13
+ super();
14
+ }
15
+
16
+ get selector() {
17
+ return this.getAttribute('selector') || 'input';
18
+ }
19
+
20
+ get locale() {
21
+ return this.getAttribute('locale') || '';
22
+ }
23
+
24
+ // todo: Currently not support single option attributes
25
+ getOptions() {
26
+ const options: any = {};
27
+ const ignore = [
28
+ 'selector'
29
+ ];
30
+
31
+ this.getAttributeNames().forEach((name) => {
32
+ if (ignore.indexOf(name) !== -1) {
33
+ return;
34
+ }
35
+
36
+ options[name] = this.getAttribute(name);
37
+ });
38
+
39
+ return options;
40
+ }
41
+
42
+ get $input(): HTMLInputElement {
43
+ return this.querySelector<HTMLInputElement>('input')!;
44
+ }
45
+
46
+ async connectedCallback() {
47
+ let options: flatpickr.Options.Options = JSON.parse(this.getAttribute('options') || '{}') || {};
48
+
49
+ options.autoFillDefaultTime = true;
50
+ const now = new Date();
51
+ options.defaultHour = now.getHours();
52
+ options.defaultMinute = now.getMinutes();
53
+ options.defaultSeconds = now.getSeconds();
54
+
55
+ options = await this.handleOptions(options);
56
+
57
+ this.instance = flatpickr(
58
+ this.querySelector<HTMLElement>(this.selector)!,
59
+ options
60
+ );
61
+
62
+ // If no value, set default time on open
63
+ this.instance.config.onOpen.push(() => {
64
+ if (this.instance.input.value === '') {
65
+ const now = new Date();
66
+ this.instance.jumpToDate(now);
67
+ this.instance.config.defaultHour = now.getHours();
68
+ this.instance.config.defaultMinute = now.getMinutes();
69
+ this.instance.config.defaultSeconds = now.getSeconds();
70
+ }
71
+ });
72
+
73
+ this.querySelector('[data-toggle]')?.addEventListener('click', () => {
74
+ setTimeout(() => {
75
+ this.querySelector<HTMLInputElement>('[data-input]')?.focus();
76
+ }, 0);
77
+ });
78
+ }
79
+
80
+ async handleOptions(options: flatpickr.Options.Options): Promise<flatpickr.Options.Options> {
81
+ options.plugins = options.plugins || [];
82
+
83
+ await Promise.all([
84
+ this.handleLocale(options),
85
+ this.handleMonthSelect(options)
86
+ ]);
87
+
88
+ return options;
89
+ }
90
+
91
+ private async handleLocale(options: Record<string, any>) {
92
+ if (this.locale) {
93
+ await useImport(`@flatpickr/l10n/${this.locale}.js`);
94
+
95
+ options.locale = this.locale.replace(/-/, '_');
96
+ }
97
+
98
+ return options;
99
+ }
100
+
101
+ private async handleMonthSelect(options: Record<string, any>) {
102
+ if (options.monthSelect) {
103
+ useCssImport('flatpickr/dist/plugins/monthSelect/style.css');
104
+ const { default: monthSelect } = await import('flatpickr/dist/plugins/monthSelect');
105
+
106
+ if (typeof options.monthSelect === 'boolean') {
107
+ options.monthSelect = {
108
+ shorthand: true,
109
+ dateFormat: 'Y-m',
110
+ altFormat: 'Y-m'
111
+ };
112
+ }
113
+
114
+ options.plugins.push(monthSelect(options.monthSelect));
115
+ }
116
+
117
+ return options;
118
+ }
119
+
120
+ getInstance() {
121
+ return this.instance;
122
+ }
123
+ }
124
+
125
+ async function init() {
126
+ injectCssToDocument(css);
127
+ customElements.define(FlatpickrElement.is, FlatpickrElement);
128
+ }
129
+
130
+ export const ready = init();
@@ -1,179 +1,179 @@
1
- import type { IFrameModalElement } from './iframe-modal';
2
- import { data } from '../data';
3
- import { __, highlight, html, selectOne, slideUp } from '../service';
4
- import { template } from 'lodash-es';
5
-
6
- export type ModalSelectCallback = (item: any) => void;
7
-
8
- export function createCallback(type: 'list' | 'single', selector: string, modalSelector: string): ModalSelectCallback {
9
- switch (type) {
10
- // case 'tag':
11
- // return () => {
12
- //
13
- // };
14
- case 'list':
15
- return (item: any) => {
16
- const modalList = document.querySelector(selector) as any as ModalListSelectElement;
17
-
18
- if (!modalList.querySelector(`[data-value="${item.value}"]`)) {
19
- modalList.appendItem(item, true);
20
-
21
- selectOne<IFrameModalElement>(modalSelector)?.close();
22
- } else {
23
- alert(__('unicorn.field.modal.already.selected'));
24
- }
25
- };
26
-
27
- case 'single':
28
- default:
29
- return (item) => {
30
- const element = document.querySelector<HTMLDivElement>(selector)!;
31
-
32
- const image = element.querySelector<HTMLDivElement>('[data-role=image]')!;
33
- const title = element.querySelector<HTMLInputElement>('[data-role=title]')!;
34
- const store = element.querySelector<HTMLInputElement>('[data-role=value]')!;
35
-
36
- if (image && item.image) {
37
- image.style.backgroundImage = `url(${item.image});`;
38
- }
39
-
40
- title.value = item.title || '';
41
- store.value = item.value || '';
42
-
43
- store.dispatchEvent(new CustomEvent('change'));
44
-
45
- selectOne<IFrameModalElement>(modalSelector)?.close();
46
-
47
- highlight(title);
48
- };
49
- }
50
- }
51
-
52
- interface ModalListOptions {
53
- modalSelector: string;
54
- itemTemplate: string;
55
- sortable: boolean;
56
- dataKey: string;
57
- max: number;
58
- }
59
-
60
- class ModalListSelectElement extends HTMLElement {
61
- static is = 'uni-modal-list';
62
-
63
- itemTemplate!: ReturnType<typeof template>;
64
- options!: ModalListOptions;
65
-
66
- get listContainer() {
67
- return this.querySelector<HTMLDivElement>('[data-role=list-container]')!;
68
- }
69
-
70
- get modal() {
71
- return document.querySelector<IFrameModalElement>(this.options.modalSelector);
72
- }
73
-
74
- get items(): Element[] {
75
- return Array.from(this.listContainer.children);
76
- }
77
-
78
- connectedCallback() {
79
- this.options = JSON.parse(this.getAttribute('options') || '{}');
80
- this.itemTemplate = template(document.querySelector(this.options.itemTemplate)!.innerHTML);
81
-
82
- const emptyInput = this.querySelector<HTMLInputElement>('[data-role=empty]');
83
-
84
- if (emptyInput) {
85
- emptyInput.name = emptyInput.dataset.name || '';
86
- }
87
-
88
- if (this.options.sortable) {
89
- import('sortablejs').then(({ default: Sortable }) => {
90
- new Sortable(this.listContainer, { handle: '.h-drag-handle', animation: 150 });
91
- });
92
- }
93
-
94
- const selectButton = this.querySelector<HTMLButtonElement>('[data-role=select]')!;
95
- selectButton.addEventListener('click', (e) => {
96
- this.open(e);
97
- });
98
-
99
- this.querySelector('[data-role=clear]')?.addEventListener('click', () => {
100
- this.items.forEach((item) => {
101
- item.querySelector<HTMLButtonElement>('[data-role=remove]')?.click();
102
- });
103
- });
104
-
105
- selectButton.style.pointerEvents = '';
106
-
107
- this.render();
108
- }
109
-
110
- render() {
111
- const items: Record<string, any>[] = data('unicorn.modal-field')[this.options.dataKey] || [];
112
-
113
- items.forEach((item) => {
114
- this.appendItem(item);
115
- });
116
- }
117
-
118
- appendItem(item: Record<string, any>, highlights = false) {
119
- const itemHtml = html(this.itemTemplate({ item }));
120
-
121
- itemHtml.dataset.value = item.value;
122
- itemHtml.querySelector<HTMLButtonElement>('[data-role=remove]')?.addEventListener('click', () => {
123
- slideUp(itemHtml).then(() => {
124
- itemHtml.remove();
125
- this.toggleRequired();
126
- });
127
- });
128
-
129
- this.listContainer.appendChild(itemHtml);
130
- this.toggleRequired();
131
-
132
- if (highlights) {
133
- highlight(itemHtml);
134
- }
135
- }
136
-
137
- toggleRequired() {
138
- const placeholder = this.querySelector<HTMLInputElement>('[data-role=validation-placeholder]');
139
-
140
- if (placeholder) {
141
- placeholder.disabled = this.listContainer.children.length !== 0;
142
- }
143
- }
144
-
145
- open(event: Event) {
146
- event.preventDefault();
147
- event.stopPropagation();
148
-
149
- const max = this.options.max;
150
-
151
- const target = event.target as HTMLAnchorElement;
152
-
153
- if (!max) {
154
- this.modal?.open(target.href, { size: 'modal-xl' });
155
- return;
156
- }
157
-
158
- if (this.listContainer.children.length >= max) {
159
- alert(
160
- __('unicorn.field.modal.max.selected', max)
161
- );
162
-
163
- return;
164
- }
165
-
166
- this.modal?.open(target.href, { size: 'modal-xl' });
167
- }
168
- }
169
-
170
- async function init() {
171
- customElements.define(ModalListSelectElement.is, ModalListSelectElement);
172
- }
173
-
174
- export const ready = init();
175
-
176
- export interface ModalSelectModule {
177
- createCallback: typeof createCallback;
178
- ready: typeof ready;
179
- }
1
+ import type { IFrameModalElement } from './iframe-modal';
2
+ import { data } from '../data';
3
+ import { __, highlight, html, selectOne, slideUp } from '../service';
4
+ import { template } from 'lodash-es';
5
+
6
+ export type ModalSelectCallback = (item: any) => void;
7
+
8
+ export function createCallback(type: 'list' | 'single', selector: string, modalSelector: string): ModalSelectCallback {
9
+ switch (type) {
10
+ // case 'tag':
11
+ // return () => {
12
+ //
13
+ // };
14
+ case 'list':
15
+ return (item: any) => {
16
+ const modalList = document.querySelector(selector) as any as ModalListSelectElement;
17
+
18
+ if (!modalList.querySelector(`[data-value="${item.value}"]`)) {
19
+ modalList.appendItem(item, true);
20
+
21
+ selectOne<IFrameModalElement>(modalSelector)?.close();
22
+ } else {
23
+ alert(__('unicorn.field.modal.already.selected'));
24
+ }
25
+ };
26
+
27
+ case 'single':
28
+ default:
29
+ return (item) => {
30
+ const element = document.querySelector<HTMLDivElement>(selector)!;
31
+
32
+ const image = element.querySelector<HTMLDivElement>('[data-role=image]')!;
33
+ const title = element.querySelector<HTMLInputElement>('[data-role=title]')!;
34
+ const store = element.querySelector<HTMLInputElement>('[data-role=value]')!;
35
+
36
+ if (image && item.image) {
37
+ image.style.backgroundImage = `url(${item.image});`;
38
+ }
39
+
40
+ title.value = item.title || '';
41
+ store.value = item.value || '';
42
+
43
+ store.dispatchEvent(new CustomEvent('change'));
44
+
45
+ selectOne<IFrameModalElement>(modalSelector)?.close();
46
+
47
+ highlight(title);
48
+ };
49
+ }
50
+ }
51
+
52
+ interface ModalListOptions {
53
+ modalSelector: string;
54
+ itemTemplate: string;
55
+ sortable: boolean;
56
+ dataKey: string;
57
+ max: number;
58
+ }
59
+
60
+ class ModalListSelectElement extends HTMLElement {
61
+ static is = 'uni-modal-list';
62
+
63
+ itemTemplate!: ReturnType<typeof template>;
64
+ options!: ModalListOptions;
65
+
66
+ get listContainer() {
67
+ return this.querySelector<HTMLDivElement>('[data-role=list-container]')!;
68
+ }
69
+
70
+ get modal() {
71
+ return document.querySelector<IFrameModalElement>(this.options.modalSelector);
72
+ }
73
+
74
+ get items(): Element[] {
75
+ return Array.from(this.listContainer.children);
76
+ }
77
+
78
+ connectedCallback() {
79
+ this.options = JSON.parse(this.getAttribute('options') || '{}');
80
+ this.itemTemplate = template(document.querySelector(this.options.itemTemplate)!.innerHTML);
81
+
82
+ const emptyInput = this.querySelector<HTMLInputElement>('[data-role=empty]');
83
+
84
+ if (emptyInput) {
85
+ emptyInput.name = emptyInput.dataset.name || '';
86
+ }
87
+
88
+ if (this.options.sortable) {
89
+ import('sortablejs').then(({ default: Sortable }) => {
90
+ new Sortable(this.listContainer, { handle: '.h-drag-handle', animation: 150 });
91
+ });
92
+ }
93
+
94
+ const selectButton = this.querySelector<HTMLButtonElement>('[data-role=select]')!;
95
+ selectButton.addEventListener('click', (e) => {
96
+ this.open(e);
97
+ });
98
+
99
+ this.querySelector('[data-role=clear]')?.addEventListener('click', () => {
100
+ this.items.forEach((item) => {
101
+ item.querySelector<HTMLButtonElement>('[data-role=remove]')?.click();
102
+ });
103
+ });
104
+
105
+ selectButton.style.pointerEvents = '';
106
+
107
+ this.render();
108
+ }
109
+
110
+ render() {
111
+ const items: Record<string, any>[] = data('unicorn.modal-field')[this.options.dataKey] || [];
112
+
113
+ items.forEach((item) => {
114
+ this.appendItem(item);
115
+ });
116
+ }
117
+
118
+ appendItem(item: Record<string, any>, highlights = false) {
119
+ const itemHtml = html(this.itemTemplate({ item }));
120
+
121
+ itemHtml.dataset.value = item.value;
122
+ itemHtml.querySelector<HTMLButtonElement>('[data-role=remove]')?.addEventListener('click', () => {
123
+ slideUp(itemHtml).then(() => {
124
+ itemHtml.remove();
125
+ this.toggleRequired();
126
+ });
127
+ });
128
+
129
+ this.listContainer.appendChild(itemHtml);
130
+ this.toggleRequired();
131
+
132
+ if (highlights) {
133
+ highlight(itemHtml);
134
+ }
135
+ }
136
+
137
+ toggleRequired() {
138
+ const placeholder = this.querySelector<HTMLInputElement>('[data-role=validation-placeholder]');
139
+
140
+ if (placeholder) {
141
+ placeholder.disabled = this.listContainer.children.length !== 0;
142
+ }
143
+ }
144
+
145
+ open(event: Event) {
146
+ event.preventDefault();
147
+ event.stopPropagation();
148
+
149
+ const max = this.options.max;
150
+
151
+ const target = event.target as HTMLAnchorElement;
152
+
153
+ if (!max) {
154
+ this.modal?.open(target.href, { size: 'modal-xl' });
155
+ return;
156
+ }
157
+
158
+ if (this.listContainer.children.length >= max) {
159
+ alert(
160
+ __('unicorn.field.modal.max.selected', max)
161
+ );
162
+
163
+ return;
164
+ }
165
+
166
+ this.modal?.open(target.href, { size: 'modal-xl' });
167
+ }
168
+ }
169
+
170
+ async function init() {
171
+ customElements.define(ModalListSelectElement.is, ModalListSelectElement);
172
+ }
173
+
174
+ export const ready = init();
175
+
176
+ export interface ModalSelectModule {
177
+ createCallback: typeof createCallback;
178
+ ready: typeof ready;
179
+ }
@@ -1,31 +1,31 @@
1
- import { data } from '../data';
2
- import { useCssImport } from '../service';
3
- import { createApp } from 'vue';
4
- import ModalTreeApp from '../vue/components/ModalTree/ModalTreeApp.vue';
5
-
6
- const app = createApp({
7
- name: 'modal-tree',
8
- components: {
9
- ModalTreeApp
10
- }
11
- });
12
- app.config.globalProperties.$getData = data;
13
-
14
- class ModalTreeElement extends HTMLElement {
15
- static is = 'modal-tree';
16
-
17
- vm: any;
18
-
19
- connectedCallback() {
20
- if (!this.vm) {
21
- this.vm = app.mount(this);
22
- }
23
- }
24
- }
25
-
26
- async function init() {
27
- customElements.define(ModalTreeElement.is, ModalTreeElement);
28
- await useCssImport('@vue-animate');
29
- }
30
-
31
- export const ready = init();
1
+ import { data } from '../data';
2
+ import { useCssImport } from '../service';
3
+ import { createApp } from 'vue';
4
+ import ModalTreeApp from '../vue/components/ModalTree/ModalTreeApp.vue';
5
+
6
+ const app = createApp({
7
+ name: 'modal-tree',
8
+ components: {
9
+ ModalTreeApp
10
+ }
11
+ });
12
+ app.config.globalProperties.$getData = data;
13
+
14
+ class ModalTreeElement extends HTMLElement {
15
+ static is = 'modal-tree';
16
+
17
+ vm: any;
18
+
19
+ connectedCallback() {
20
+ if (!this.vm) {
21
+ this.vm = app.mount(this);
22
+ }
23
+ }
24
+ }
25
+
26
+ async function init() {
27
+ customElements.define(ModalTreeElement.is, ModalTreeElement);
28
+ await useCssImport('@vue-animate');
29
+ }
30
+
31
+ export const ready = init();