@windwalker-io/unicorn-next 0.1.0 → 0.1.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/.editorconfig +18 -18
- package/.gulp.json +7 -7
- package/bin/release.mjs +47 -47
- package/dist/chunks/button-radio.js.map +1 -1
- package/dist/chunks/checkboxes-multi-select.js.map +1 -1
- package/dist/chunks/field-cascade-select.js.map +1 -1
- package/dist/chunks/field-file-drag.js.map +1 -1
- package/dist/chunks/field-flatpickr.js.map +1 -1
- package/dist/chunks/field-modal-select.js.map +1 -1
- package/dist/chunks/field-modal-tree.js +2 -2
- package/dist/chunks/field-modal-tree.js.map +1 -1
- package/dist/chunks/field-multi-uploader.js.map +1 -1
- package/dist/chunks/field-repeatable.js.map +1 -1
- package/dist/chunks/field-single-image-drag.js.map +1 -1
- package/dist/chunks/form.js +1 -1
- package/dist/chunks/form.js.map +1 -1
- package/dist/chunks/grid.js.map +1 -1
- package/dist/chunks/http-client.js.map +1 -1
- package/dist/chunks/iframe-modal.js.map +1 -1
- package/dist/chunks/keep-tab.js +1 -1
- package/dist/chunks/keep-tab.js.map +1 -1
- package/dist/chunks/legacy.js +3 -3
- package/dist/chunks/legacy.js.map +1 -1
- package/dist/chunks/list-dependent.js.map +1 -1
- package/dist/chunks/s3-multipart-uploader.js.map +1 -1
- package/dist/chunks/s3-uploader.js.map +1 -1
- package/dist/chunks/show-on.js.map +1 -1
- package/dist/chunks/tinymce.js +14 -4
- package/dist/chunks/tinymce.js.map +1 -1
- package/dist/chunks/ui-bootstrap5.js +9 -2
- package/dist/chunks/ui-bootstrap5.js.map +1 -1
- package/dist/chunks/unicorn.js +94 -46
- package/dist/chunks/unicorn.js.map +1 -1
- package/dist/chunks/validation.js.map +1 -1
- package/dist/editor.css +1 -1
- package/dist/index.d.ts +55 -36
- package/dist/multi-level-menu.css +1 -1
- package/dist/switcher.css +1 -1
- package/dist/unicorn.js +22 -22
- package/fusionfile.mjs +155 -155
- package/package.json +102 -102
- package/scss/bootstrap/multi-level-menu.scss +121 -121
- package/scss/editor.scss +116 -116
- package/scss/field/file-drag.scss +102 -102
- package/scss/field/single-image-drag.scss +88 -88
- package/scss/field/vue-drag-uploader.scss +160 -160
- package/scss/switcher.scss +156 -156
- package/src/app.ts +128 -128
- package/src/bootstrap/button-radio.ts +208 -208
- package/src/bootstrap/keep-tab.ts +155 -155
- package/src/composable/index.ts +21 -21
- package/src/composable/useCheckboxesMultiSelect.ts +22 -22
- package/src/composable/useFieldCascadeSelect.ts +9 -9
- package/src/composable/useFieldFileDrag.ts +9 -9
- package/src/composable/useFieldFlatpickr.ts +3 -3
- package/src/composable/useFieldModalSelect.ts +6 -6
- package/src/composable/useFieldModalTree.ts +3 -3
- package/src/composable/useFieldMultiUploader.ts +3 -3
- package/src/composable/useFieldRepeatable.ts +9 -9
- package/src/composable/useFieldSingleImageDrag.ts +5 -5
- package/src/composable/useForm.ts +43 -43
- package/src/composable/useGrid.ts +57 -57
- package/src/composable/useHttp.ts +9 -8
- package/src/composable/useIframeModal.ts +9 -9
- package/src/composable/useListDependent.ts +26 -26
- package/src/composable/useQueue.ts +13 -13
- package/src/composable/useS3Uploader.ts +32 -32
- package/src/composable/useShowOn.ts +9 -9
- package/src/composable/useStack.ts +13 -13
- package/src/composable/useTinymce.ts +29 -29
- package/src/composable/useTomSelect.ts +72 -72
- package/src/composable/useUIBootstrap5.ts +48 -48
- package/src/composable/useUniDirective.ts +32 -32
- package/src/composable/useValidation.ts +39 -39
- package/src/data.ts +34 -36
- package/src/events.ts +82 -73
- package/src/legacy/legacy.ts +186 -186
- package/src/legacy/loader.ts +125 -125
- package/src/module/checkboxes-multi-select.ts +54 -54
- package/src/module/field-cascade-select.ts +292 -292
- package/src/module/field-file-drag.ts +292 -292
- package/src/module/field-flatpickr.ts +127 -127
- package/src/module/field-modal-select.ts +174 -174
- package/src/module/field-modal-tree.ts +27 -27
- package/src/module/field-multi-uploader.ts +361 -361
- package/src/module/field-repeatable.ts +202 -202
- package/src/module/field-single-image-drag.ts +468 -468
- package/src/module/form.ts +223 -223
- package/src/module/grid.ts +465 -465
- package/src/module/http-client.ts +248 -243
- package/src/module/iframe-modal.ts +167 -167
- package/src/module/list-dependent.ts +321 -321
- package/src/module/s3-multipart-uploader.ts +300 -300
- package/src/module/s3-uploader.ts +234 -234
- package/src/module/show-on.ts +173 -173
- package/src/module/tinymce.ts +279 -263
- package/src/module/ui-bootstrap5.ts +116 -107
- package/src/module/validation.ts +1019 -1019
- package/src/plugin/index.ts +1 -1
- package/src/plugin/php-adapter.ts +65 -65
- package/src/polyfill/form-request-submit.ts +31 -31
- package/src/polyfill/index.ts +9 -9
- package/src/service/animate.ts +58 -58
- package/src/service/crypto.ts +27 -27
- package/src/service/dom-watcher.ts +62 -62
- package/src/service/dom.ts +265 -265
- package/src/service/helper.ts +48 -48
- package/src/service/index.ts +10 -10
- package/src/service/lang.ts +122 -122
- package/src/service/loader.ts +152 -152
- package/src/service/router.ts +118 -118
- package/src/service/ui.ts +525 -497
- package/src/service/uri.ts +106 -106
- package/src/types/base.ts +9 -9
- package/src/types/index.ts +4 -4
- package/src/types/modal-tree.ts +12 -12
- package/src/types/plugin.ts +6 -6
- package/src/types/shims.d.ts +18 -18
- package/src/types/ui.ts +6 -6
- package/src/unicorn.ts +79 -63
- package/src/utilities/arr.ts +25 -25
- package/src/utilities/base.ts +9 -9
- package/src/utilities/data.ts +48 -48
- package/src/utilities/index.ts +5 -5
- package/src/utilities/tree.ts +20 -20
- package/src/vue/components/ModalTree/ModalTreeApp.vue +175 -175
- package/src/vue/components/ModalTree/TreeItem.vue +262 -262
- package/src/vue/components/ModalTree/TreeModal.vue +225 -225
- package/tests/test.js +4 -4
- package/tsconfig.js.json +25 -25
- package/tsconfig.json +17 -17
- package/vite.assets.config.ts +61 -61
- package/vite.config.test.ts +36 -36
- package/vite.config.ts +112 -112
- package/dist/unicorn-next.css +0 -12
|
@@ -1,127 +1,127 @@
|
|
|
1
|
-
import { useCssImport, useImport, injectCssToDocument } from '../service';
|
|
2
|
-
import flatpickr from 'flatpickr';
|
|
3
|
-
import css from 'flatpickr/dist/flatpickr.css?inline';
|
|
4
|
-
|
|
5
|
-
injectCssToDocument(css);
|
|
6
|
-
|
|
7
|
-
class FlatpickrElement extends HTMLElement {
|
|
8
|
-
static get is() {
|
|
9
|
-
return 'uni-flatpickr';
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
instance!: flatpickr.Instance;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
super();
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
get selector() {
|
|
19
|
-
return this.getAttribute('selector') || 'input';
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
get locale() {
|
|
23
|
-
return this.getAttribute('locale') || '';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
// todo: Currently not support single option attributes
|
|
27
|
-
getOptions() {
|
|
28
|
-
const options: any = {};
|
|
29
|
-
const ignore = [
|
|
30
|
-
'selector'
|
|
31
|
-
];
|
|
32
|
-
|
|
33
|
-
this.getAttributeNames().forEach((name) => {
|
|
34
|
-
if (ignore.indexOf(name) !== -1) {
|
|
35
|
-
return;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
options[name] = this.getAttribute(name);
|
|
39
|
-
});
|
|
40
|
-
|
|
41
|
-
return options;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
get $input(): HTMLInputElement {
|
|
45
|
-
return this.querySelector<HTMLInputElement>('input')!;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
async connectedCallback() {
|
|
49
|
-
let options: flatpickr.Options.Options = JSON.parse(this.getAttribute('options') || '{}') || {};
|
|
50
|
-
|
|
51
|
-
options.autoFillDefaultTime = true;
|
|
52
|
-
const now = new Date();
|
|
53
|
-
options.defaultHour = now.getHours();
|
|
54
|
-
options.defaultMinute = now.getMinutes();
|
|
55
|
-
options.defaultSeconds = now.getSeconds();
|
|
56
|
-
|
|
57
|
-
options = await this.handleOptions(options);
|
|
58
|
-
|
|
59
|
-
this.instance = flatpickr(
|
|
60
|
-
this.querySelector<HTMLElement>(this.selector)!,
|
|
61
|
-
options
|
|
62
|
-
);
|
|
63
|
-
|
|
64
|
-
// If no value, set default time on open
|
|
65
|
-
this.instance.config.onOpen.push(() => {
|
|
66
|
-
if (this.instance.input.value === '') {
|
|
67
|
-
const now = new Date();
|
|
68
|
-
this.instance.jumpToDate(now);
|
|
69
|
-
this.instance.config.defaultHour = now.getHours();
|
|
70
|
-
this.instance.config.defaultMinute = now.getMinutes();
|
|
71
|
-
this.instance.config.defaultSeconds = now.getSeconds();
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
this.querySelector('[data-toggle]')?.addEventListener('click', () => {
|
|
76
|
-
setTimeout(() => {
|
|
77
|
-
this.querySelector<HTMLInputElement>('[data-input]')?.focus();
|
|
78
|
-
}, 0);
|
|
79
|
-
});
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
async handleOptions(options: flatpickr.Options.Options): Promise<flatpickr.Options.Options> {
|
|
83
|
-
options.plugins = options.plugins || [];
|
|
84
|
-
|
|
85
|
-
await Promise.all([
|
|
86
|
-
this.handleLocale(options),
|
|
87
|
-
this.handleMonthSelect(options)
|
|
88
|
-
]);
|
|
89
|
-
|
|
90
|
-
return options;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
private async handleLocale(options: Record<string, any>) {
|
|
94
|
-
if (this.locale) {
|
|
95
|
-
await useImport(`flatpickr/dist/l10n/${this.locale}.js`);
|
|
96
|
-
|
|
97
|
-
options.locale = this.locale.replace(/-/, '_');
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
return options;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
private async handleMonthSelect(options: Record<string, any>) {
|
|
104
|
-
if (options.monthSelect) {
|
|
105
|
-
useCssImport('flatpickr/dist/plugins/monthSelect/style.css');
|
|
106
|
-
const { default: monthSelect } = await import('flatpickr/dist/plugins/monthSelect');
|
|
107
|
-
|
|
108
|
-
if (typeof options.monthSelect === 'boolean') {
|
|
109
|
-
options.monthSelect = {
|
|
110
|
-
shorthand: true,
|
|
111
|
-
dateFormat: 'Y-m',
|
|
112
|
-
altFormat: 'Y-m'
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
options.plugins.push(monthSelect(options.monthSelect));
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
return options;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
getInstance() {
|
|
123
|
-
return this.instance;
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
customElements.define(FlatpickrElement.is, FlatpickrElement);
|
|
1
|
+
import { useCssImport, useImport, injectCssToDocument } from '../service';
|
|
2
|
+
import flatpickr from 'flatpickr';
|
|
3
|
+
import css from 'flatpickr/dist/flatpickr.css?inline';
|
|
4
|
+
|
|
5
|
+
injectCssToDocument(css);
|
|
6
|
+
|
|
7
|
+
class FlatpickrElement extends HTMLElement {
|
|
8
|
+
static get is() {
|
|
9
|
+
return 'uni-flatpickr';
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
instance!: flatpickr.Instance;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get selector() {
|
|
19
|
+
return this.getAttribute('selector') || 'input';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get locale() {
|
|
23
|
+
return this.getAttribute('locale') || '';
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
// todo: Currently not support single option attributes
|
|
27
|
+
getOptions() {
|
|
28
|
+
const options: any = {};
|
|
29
|
+
const ignore = [
|
|
30
|
+
'selector'
|
|
31
|
+
];
|
|
32
|
+
|
|
33
|
+
this.getAttributeNames().forEach((name) => {
|
|
34
|
+
if (ignore.indexOf(name) !== -1) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
options[name] = this.getAttribute(name);
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
return options;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
get $input(): HTMLInputElement {
|
|
45
|
+
return this.querySelector<HTMLInputElement>('input')!;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
async connectedCallback() {
|
|
49
|
+
let options: flatpickr.Options.Options = JSON.parse(this.getAttribute('options') || '{}') || {};
|
|
50
|
+
|
|
51
|
+
options.autoFillDefaultTime = true;
|
|
52
|
+
const now = new Date();
|
|
53
|
+
options.defaultHour = now.getHours();
|
|
54
|
+
options.defaultMinute = now.getMinutes();
|
|
55
|
+
options.defaultSeconds = now.getSeconds();
|
|
56
|
+
|
|
57
|
+
options = await this.handleOptions(options);
|
|
58
|
+
|
|
59
|
+
this.instance = flatpickr(
|
|
60
|
+
this.querySelector<HTMLElement>(this.selector)!,
|
|
61
|
+
options
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
// If no value, set default time on open
|
|
65
|
+
this.instance.config.onOpen.push(() => {
|
|
66
|
+
if (this.instance.input.value === '') {
|
|
67
|
+
const now = new Date();
|
|
68
|
+
this.instance.jumpToDate(now);
|
|
69
|
+
this.instance.config.defaultHour = now.getHours();
|
|
70
|
+
this.instance.config.defaultMinute = now.getMinutes();
|
|
71
|
+
this.instance.config.defaultSeconds = now.getSeconds();
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
this.querySelector('[data-toggle]')?.addEventListener('click', () => {
|
|
76
|
+
setTimeout(() => {
|
|
77
|
+
this.querySelector<HTMLInputElement>('[data-input]')?.focus();
|
|
78
|
+
}, 0);
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
async handleOptions(options: flatpickr.Options.Options): Promise<flatpickr.Options.Options> {
|
|
83
|
+
options.plugins = options.plugins || [];
|
|
84
|
+
|
|
85
|
+
await Promise.all([
|
|
86
|
+
this.handleLocale(options),
|
|
87
|
+
this.handleMonthSelect(options)
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
return options;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
private async handleLocale(options: Record<string, any>) {
|
|
94
|
+
if (this.locale) {
|
|
95
|
+
await useImport(`flatpickr/dist/l10n/${this.locale}.js`);
|
|
96
|
+
|
|
97
|
+
options.locale = this.locale.replace(/-/, '_');
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
return options;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
private async handleMonthSelect(options: Record<string, any>) {
|
|
104
|
+
if (options.monthSelect) {
|
|
105
|
+
useCssImport('flatpickr/dist/plugins/monthSelect/style.css');
|
|
106
|
+
const { default: monthSelect } = await import('flatpickr/dist/plugins/monthSelect');
|
|
107
|
+
|
|
108
|
+
if (typeof options.monthSelect === 'boolean') {
|
|
109
|
+
options.monthSelect = {
|
|
110
|
+
shorthand: true,
|
|
111
|
+
dateFormat: 'Y-m',
|
|
112
|
+
altFormat: 'Y-m'
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
options.plugins.push(monthSelect(options.monthSelect));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return options;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
getInstance() {
|
|
123
|
+
return this.instance;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
customElements.define(FlatpickrElement.is, FlatpickrElement);
|
|
@@ -1,174 +1,174 @@
|
|
|
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
|
-
customElements.define(ModalListSelectElement.is, ModalListSelectElement);
|
|
171
|
-
|
|
172
|
-
export interface ModalSelectModule {
|
|
173
|
-
createCallback: typeof createCallback;
|
|
174
|
-
}
|
|
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
|
+
customElements.define(ModalListSelectElement.is, ModalListSelectElement);
|
|
171
|
+
|
|
172
|
+
export interface ModalSelectModule {
|
|
173
|
+
createCallback: typeof createCallback;
|
|
174
|
+
}
|
|
@@ -1,27 +1,27 @@
|
|
|
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
|
-
useCssImport('@vue-animate');
|
|
6
|
-
|
|
7
|
-
const app = createApp({
|
|
8
|
-
name: 'modal-tree',
|
|
9
|
-
components: {
|
|
10
|
-
ModalTreeApp
|
|
11
|
-
}
|
|
12
|
-
});
|
|
13
|
-
app.config.globalProperties.$getData = data;
|
|
14
|
-
|
|
15
|
-
class ModalTreeElement extends HTMLElement {
|
|
16
|
-
static is = 'modal-tree';
|
|
17
|
-
|
|
18
|
-
vm: any;
|
|
19
|
-
|
|
20
|
-
connectedCallback() {
|
|
21
|
-
if (!this.vm) {
|
|
22
|
-
this.vm = app.mount(this);
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
customElements.define(ModalTreeElement.is, ModalTreeElement);
|
|
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
|
+
useCssImport('@vue-animate');
|
|
6
|
+
|
|
7
|
+
const app = createApp({
|
|
8
|
+
name: 'modal-tree',
|
|
9
|
+
components: {
|
|
10
|
+
ModalTreeApp
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
app.config.globalProperties.$getData = data;
|
|
14
|
+
|
|
15
|
+
class ModalTreeElement extends HTMLElement {
|
|
16
|
+
static is = 'modal-tree';
|
|
17
|
+
|
|
18
|
+
vm: any;
|
|
19
|
+
|
|
20
|
+
connectedCallback() {
|
|
21
|
+
if (!this.vm) {
|
|
22
|
+
this.vm = app.mount(this);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
customElements.define(ModalTreeElement.is, ModalTreeElement);
|