naive-ui 2.30.4 → 2.30.7
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.zh-CN.md +2 -2
- package/dist/index.js +2321 -1375
- package/dist/index.prod.js +2 -2
- package/es/_internal/close/src/Close.js +1 -1
- package/es/_internal/scrollbar/src/Scrollbar.js +1 -2
- package/es/_internal/selection/src/Selection.js +5 -3
- package/es/_utils/dom/index.d.ts +1 -0
- package/es/_utils/dom/index.js +1 -0
- package/es/_utils/dom/is-document.d.ts +1 -0
- package/es/_utils/dom/is-document.js +3 -0
- package/es/_utils/index.d.ts +2 -1
- package/es/_utils/index.js +2 -1
- package/es/_utils/vue/index.d.ts +2 -0
- package/es/_utils/vue/index.js +2 -0
- package/es/_utils/vue/is-node-v-show-false.d.ts +2 -0
- package/es/_utils/vue/is-node-v-show-false.js +6 -0
- package/es/{_internal/scrollbar/src/Wrapper.d.ts → _utils/vue/wrapper.d.ts} +0 -0
- package/es/{_internal/scrollbar/src/Wrapper.js → _utils/vue/wrapper.js} +0 -0
- package/es/back-top/src/BackTop.d.ts +1 -1
- package/es/back-top/src/BackTop.js +24 -31
- package/es/button/src/styles/index.cssr.js +3 -0
- package/es/color-picker/src/ColorInputUnit.js +1 -1
- package/es/data-table/src/DataTable.d.ts +5 -2
- package/es/data-table/src/DataTable.js +3 -2
- package/es/data-table/src/TableParts/Body.d.ts +1 -0
- package/es/data-table/src/TableParts/Body.js +5 -7
- package/es/data-table/src/TableParts/Cell.d.ts +11 -1
- package/es/data-table/src/TableParts/Cell.js +19 -6
- package/es/data-table/src/interface.d.ts +5 -2
- package/es/data-table/src/styles/index.cssr.js +7 -2
- package/es/data-table/src/use-check.js +11 -3
- package/es/date-picker/src/DatePicker.d.ts +40 -0
- package/es/date-picker/src/DatePicker.js +15 -3
- package/es/date-picker/src/config.d.ts +1 -1
- package/es/date-picker/src/panel/date.d.ts +4 -0
- package/es/date-picker/src/panel/daterange.d.ts +7 -1
- package/es/date-picker/src/panel/datetime.d.ts +4 -0
- package/es/date-picker/src/panel/datetimerange.d.ts +7 -1
- package/es/date-picker/src/panel/month.d.ts +4 -0
- package/es/date-picker/src/panel/monthrange.d.ts +11 -5
- package/es/date-picker/src/panel/monthrange.js +13 -7
- package/es/date-picker/src/panel/panelHeader.d.ts +8 -0
- package/es/date-picker/src/panel/use-calendar.d.ts +4 -0
- package/es/date-picker/src/panel/use-dual-calendar.d.ts +9 -3
- package/es/date-picker/src/panel/use-dual-calendar.js +26 -6
- package/es/date-picker/src/panel/use-panel-common.d.ts +4 -0
- package/es/date-picker/src/utils.d.ts +1 -1
- package/es/date-picker/src/utils.js +2 -2
- package/es/date-picker/styles/_common.d.ts +4 -0
- package/es/date-picker/styles/_common.js +5 -1
- package/es/date-picker/styles/light.d.ts +8 -0
- package/es/drawer/src/DrawerBodyWrapper.js +1 -1
- package/es/grid/src/Grid.d.ts +3 -0
- package/es/grid/src/Grid.js +47 -9
- package/es/grid/src/GridItem.js +2 -1
- package/es/image/src/Image.d.ts +10 -0
- package/es/image/src/Image.js +42 -8
- package/es/image/src/utils.d.ts +11 -0
- package/es/image/src/utils.js +81 -0
- package/es/input/src/styles/input-group-label.cssr.js +2 -0
- package/es/locales/common/viVN.d.ts +3 -0
- package/es/locales/common/viVN.js +113 -0
- package/es/locales/date/viVN.d.ts +3 -0
- package/es/locales/date/viVN.js +6 -0
- package/es/locales/index.d.ts +2 -0
- package/es/locales/index.js +2 -0
- package/es/modal/src/BodyWrapper.d.ts +13 -18
- package/es/modal/src/BodyWrapper.js +38 -33
- package/es/modal/src/Modal.js +12 -7
- package/es/modal/src/styles/index.cssr.js +1 -0
- package/es/notification/src/Notification.d.ts +3 -0
- package/es/notification/src/Notification.js +5 -2
- package/es/notification/src/NotificationContainer.d.ts +3 -0
- package/es/notification/src/NotificationProvider.d.ts +27 -0
- package/es/notification/src/styles/index.cssr.js +6 -3
- package/es/notification/styles/_common.d.ts +3 -0
- package/es/notification/styles/_common.js +4 -1
- package/es/notification/styles/light.d.ts +6 -0
- package/es/select/index.d.ts +1 -1
- package/es/select/src/Select.d.ts +4 -4
- package/es/select/src/Select.js +10 -1
- package/es/select/src/interface.d.ts +1 -0
- package/es/space/src/Space.d.ts +26 -0
- package/es/space/src/Space.js +53 -43
- package/es/tabs/src/Tabs.js +1 -1
- package/es/tooltip/index.d.ts +1 -1
- package/es/tree/src/Tree.d.ts +4 -3
- package/es/tree/src/Tree.js +2 -1
- package/es/tree/src/TreeNode.d.ts +1 -1
- package/es/tree/src/interface.d.ts +1 -1
- package/es/tree-select/index.d.ts +1 -1
- package/es/tree-select/src/TreeSelect.d.ts +27 -5
- package/es/tree-select/src/TreeSelect.js +19 -3
- package/es/tree-select/src/interface.d.ts +17 -1
- package/es/version.d.ts +1 -1
- package/es/version.js +1 -1
- package/lib/_internal/close/src/Close.js +1 -1
- package/lib/_internal/scrollbar/src/Scrollbar.js +2 -3
- package/lib/_internal/selection/src/Selection.js +4 -2
- package/lib/_utils/dom/index.d.ts +1 -0
- package/lib/_utils/dom/index.js +5 -0
- package/lib/_utils/dom/is-document.d.ts +1 -0
- package/lib/_utils/dom/is-document.js +7 -0
- package/lib/_utils/index.d.ts +2 -1
- package/lib/_utils/index.js +4 -1
- package/lib/_utils/vue/index.d.ts +2 -0
- package/lib/_utils/vue/index.js +5 -1
- package/lib/_utils/vue/is-node-v-show-false.d.ts +2 -0
- package/lib/_utils/vue/is-node-v-show-false.js +10 -0
- package/lib/{_internal/scrollbar/src/Wrapper.d.ts → _utils/vue/wrapper.d.ts} +0 -0
- package/lib/{_internal/scrollbar/src/Wrapper.js → _utils/vue/wrapper.js} +0 -0
- package/lib/back-top/src/BackTop.d.ts +1 -1
- package/lib/back-top/src/BackTop.js +23 -30
- package/lib/button/src/styles/index.cssr.js +3 -0
- package/lib/color-picker/src/ColorInputUnit.js +1 -1
- package/lib/data-table/src/DataTable.d.ts +5 -2
- package/lib/data-table/src/DataTable.js +3 -2
- package/lib/data-table/src/TableParts/Body.d.ts +1 -0
- package/lib/data-table/src/TableParts/Body.js +5 -7
- package/lib/data-table/src/TableParts/Cell.d.ts +11 -1
- package/lib/data-table/src/TableParts/Cell.js +19 -6
- package/lib/data-table/src/interface.d.ts +5 -2
- package/lib/data-table/src/styles/index.cssr.js +7 -2
- package/lib/data-table/src/use-check.js +11 -3
- package/lib/date-picker/src/DatePicker.d.ts +40 -0
- package/lib/date-picker/src/DatePicker.js +15 -3
- package/lib/date-picker/src/config.d.ts +1 -1
- package/lib/date-picker/src/panel/date.d.ts +4 -0
- package/lib/date-picker/src/panel/daterange.d.ts +7 -1
- package/lib/date-picker/src/panel/datetime.d.ts +4 -0
- package/lib/date-picker/src/panel/datetimerange.d.ts +7 -1
- package/lib/date-picker/src/panel/month.d.ts +4 -0
- package/lib/date-picker/src/panel/monthrange.d.ts +11 -5
- package/lib/date-picker/src/panel/monthrange.js +13 -7
- package/lib/date-picker/src/panel/panelHeader.d.ts +8 -0
- package/lib/date-picker/src/panel/use-calendar.d.ts +4 -0
- package/lib/date-picker/src/panel/use-dual-calendar.d.ts +9 -3
- package/lib/date-picker/src/panel/use-dual-calendar.js +24 -4
- package/lib/date-picker/src/panel/use-panel-common.d.ts +4 -0
- package/lib/date-picker/src/utils.d.ts +1 -1
- package/lib/date-picker/src/utils.js +2 -2
- package/lib/date-picker/styles/_common.d.ts +4 -0
- package/lib/date-picker/styles/_common.js +5 -1
- package/lib/date-picker/styles/light.d.ts +8 -0
- package/lib/drawer/src/DrawerBodyWrapper.js +1 -1
- package/lib/grid/src/Grid.d.ts +3 -0
- package/lib/grid/src/Grid.js +45 -7
- package/lib/grid/src/GridItem.js +2 -1
- package/lib/image/src/Image.d.ts +10 -0
- package/lib/image/src/Image.js +41 -7
- package/lib/image/src/utils.d.ts +11 -0
- package/lib/image/src/utils.js +86 -0
- package/lib/input/src/styles/input-group-label.cssr.js +2 -0
- package/lib/locales/common/viVN.d.ts +3 -0
- package/lib/locales/common/viVN.js +115 -0
- package/lib/locales/date/viVN.d.ts +3 -0
- package/lib/locales/date/viVN.js +11 -0
- package/lib/locales/index.d.ts +2 -0
- package/lib/locales/index.js +5 -1
- package/lib/modal/src/BodyWrapper.d.ts +13 -18
- package/lib/modal/src/BodyWrapper.js +38 -33
- package/lib/modal/src/Modal.js +12 -7
- package/lib/modal/src/styles/index.cssr.js +1 -0
- package/lib/notification/src/Notification.d.ts +3 -0
- package/lib/notification/src/Notification.js +5 -2
- package/lib/notification/src/NotificationContainer.d.ts +3 -0
- package/lib/notification/src/NotificationProvider.d.ts +27 -0
- package/lib/notification/src/styles/index.cssr.js +6 -3
- package/lib/notification/styles/_common.d.ts +3 -0
- package/lib/notification/styles/_common.js +4 -1
- package/lib/notification/styles/light.d.ts +6 -0
- package/lib/select/index.d.ts +1 -1
- package/lib/select/src/Select.d.ts +4 -4
- package/lib/select/src/Select.js +10 -1
- package/lib/select/src/interface.d.ts +1 -0
- package/lib/space/src/Space.d.ts +26 -0
- package/lib/space/src/Space.js +53 -43
- package/lib/tabs/src/Tabs.js +1 -1
- package/lib/tooltip/index.d.ts +1 -1
- package/lib/tree/src/Tree.d.ts +4 -3
- package/lib/tree/src/Tree.js +2 -1
- package/lib/tree/src/TreeNode.d.ts +1 -1
- package/lib/tree/src/interface.d.ts +1 -1
- package/lib/tree-select/index.d.ts +1 -1
- package/lib/tree-select/src/TreeSelect.d.ts +27 -5
- package/lib/tree-select/src/TreeSelect.js +19 -3
- package/lib/tree-select/src/interface.d.ts +17 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +2 -2
- package/volar.d.ts +0 -1
- package/web-types.json +100 -10
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inject, computed, watch, ref } from 'vue';
|
|
2
|
-
import { addMonths, format, getYear, getMonth, startOfMonth, isValid, startOfSecond, startOfDay, set, getDate, getTime } from 'date-fns/esm';
|
|
3
|
-
import { dateArray, strictParse, yearArray, monthArray, getDefaultTime, pluckValueFromRange } from '../utils';
|
|
2
|
+
import { addMonths, format, getYear, getMonth, startOfMonth, isValid, startOfSecond, startOfDay, set, getDate, getTime, startOfQuarter } from 'date-fns/esm';
|
|
3
|
+
import { dateArray, strictParse, yearArray, monthArray, getDefaultTime, pluckValueFromRange, quarterArray } from '../utils';
|
|
4
4
|
import { usePanelCommon, usePanelCommonProps } from './use-panel-common';
|
|
5
5
|
import { datePickerInjectionKey } from '../interface';
|
|
6
6
|
import { MONTH_ITEM_HEIGHT, START_YEAR } from '../config';
|
|
@@ -113,6 +113,14 @@ function useDualCalendar(props, type) {
|
|
|
113
113
|
const endYearArrayRef = computed(() => {
|
|
114
114
|
return yearArray(pluckValueFromRange(props.value, 'end'), nowRef.value);
|
|
115
115
|
});
|
|
116
|
+
const startQuarterArrayRef = computed(() => {
|
|
117
|
+
const startValue = pluckValueFromRange(props.value, 'start');
|
|
118
|
+
return quarterArray(startValue !== null && startValue !== void 0 ? startValue : Date.now(), startValue, nowRef.value);
|
|
119
|
+
});
|
|
120
|
+
const endQuarterArrayRef = computed(() => {
|
|
121
|
+
const endValue = pluckValueFromRange(props.value, 'end');
|
|
122
|
+
return quarterArray(endValue !== null && endValue !== void 0 ? endValue : Date.now(), endValue, nowRef.value);
|
|
123
|
+
});
|
|
116
124
|
const startMonthArrayRef = computed(() => {
|
|
117
125
|
const startValue = pluckValueFromRange(props.value, 'start');
|
|
118
126
|
return monthArray(startValue !== null && startValue !== void 0 ? startValue : Date.now(), startValue, nowRef.value);
|
|
@@ -541,11 +549,17 @@ function useDualCalendar(props, type) {
|
|
|
541
549
|
function handleColItemClick(dateItem, clickType) {
|
|
542
550
|
const { value } = props;
|
|
543
551
|
const noCurrentValue = !Array.isArray(value);
|
|
544
|
-
const itemTs = dateItem.type === 'year'
|
|
552
|
+
const itemTs = dateItem.type === 'year' && type !== 'yearrange'
|
|
545
553
|
? noCurrentValue
|
|
546
|
-
? set(dateItem.ts, {
|
|
554
|
+
? set(dateItem.ts, {
|
|
555
|
+
month: getMonth(type === 'quarterrange'
|
|
556
|
+
? startOfQuarter(new Date())
|
|
557
|
+
: new Date())
|
|
558
|
+
}).valueOf()
|
|
547
559
|
: set(dateItem.ts, {
|
|
548
|
-
month: getMonth(
|
|
560
|
+
month: getMonth(type === 'quarterrange'
|
|
561
|
+
? startOfQuarter(value[clickType === 'start' ? 0 : 1])
|
|
562
|
+
: value[clickType === 'start' ? 0 : 1])
|
|
549
563
|
}).valueOf()
|
|
550
564
|
: dateItem.ts;
|
|
551
565
|
if (noCurrentValue) {
|
|
@@ -554,6 +568,7 @@ function useDualCalendar(props, type) {
|
|
|
554
568
|
panelCommon.doUpdateValue(nextValue, props.panel);
|
|
555
569
|
justifyColumnsScrollState(nextValue, 'start');
|
|
556
570
|
justifyColumnsScrollState(nextValue, 'end');
|
|
571
|
+
panelCommon.disableTransitionOneTick();
|
|
557
572
|
return;
|
|
558
573
|
}
|
|
559
574
|
const nextValue = [value[0], value[1]];
|
|
@@ -575,6 +590,7 @@ function useDualCalendar(props, type) {
|
|
|
575
590
|
panelCommon.doUpdateValue(nextValue, props.panel);
|
|
576
591
|
switch (type) {
|
|
577
592
|
case 'monthrange':
|
|
593
|
+
case 'quarterrange':
|
|
578
594
|
panelCommon.disableTransitionOneTick();
|
|
579
595
|
if (otherPartsChanged) {
|
|
580
596
|
justifyColumnsScrollState(nextValue, 'start');
|
|
@@ -584,6 +600,10 @@ function useDualCalendar(props, type) {
|
|
|
584
600
|
justifyColumnsScrollState(nextValue, clickType);
|
|
585
601
|
}
|
|
586
602
|
break;
|
|
603
|
+
case 'yearrange':
|
|
604
|
+
panelCommon.disableTransitionOneTick();
|
|
605
|
+
justifyColumnsScrollState(nextValue, 'start');
|
|
606
|
+
justifyColumnsScrollState(nextValue, 'end');
|
|
587
607
|
}
|
|
588
608
|
}
|
|
589
609
|
function handleStartYearVlScroll() {
|
|
@@ -636,7 +656,7 @@ function useDualCalendar(props, type) {
|
|
|
636
656
|
endCalendarNextMonth,
|
|
637
657
|
endCalendarNextYear,
|
|
638
658
|
mergedIsDateDisabled,
|
|
639
|
-
changeStartEndTime, ranges: rangesRef, startCalendarMonth: startCalendarMonthRef, startCalendarYear: startCalendarYearRef, endCalendarMonth: endCalendarMonthRef, endCalendarYear: endCalendarYearRef, weekdays: weekdaysRef, startDateArray: startDateArrayRef, endDateArray: endDateArrayRef, startYearArray: startYearArrayRef, startMonthArray: startMonthArrayRef, endYearArray: endYearArrayRef, endMonthArray: endMonthArrayRef, isSelecting: isSelectingRef, handleRangeShortcutMouseenter,
|
|
659
|
+
changeStartEndTime, ranges: rangesRef, startCalendarMonth: startCalendarMonthRef, startCalendarYear: startCalendarYearRef, endCalendarMonth: endCalendarMonthRef, endCalendarYear: endCalendarYearRef, weekdays: weekdaysRef, startDateArray: startDateArrayRef, endDateArray: endDateArrayRef, startYearArray: startYearArrayRef, startMonthArray: startMonthArrayRef, startQuarterArray: startQuarterArrayRef, endYearArray: endYearArrayRef, endMonthArray: endMonthArrayRef, endQuarterArray: endQuarterArrayRef, isSelecting: isSelectingRef, handleRangeShortcutMouseenter,
|
|
640
660
|
handleRangeShortcutClick }, panelCommon), validation), childComponentRefs), {
|
|
641
661
|
// datetimerangeonly
|
|
642
662
|
startDateDisplayString: startDateInput, endDateInput: endDateInputRef, timePickerSize: panelCommon.timePickerSize, startTimeValue: startTimeValueRef, endTimeValue: endTimeValueRef, datePickerSlots, shortcuts: shortcutsRef, startCalendarDateTime: startCalendarDateTimeRef, endCalendarDateTime: endCalendarDateTimeRef, justifyColumnsScrollState, handleFocusDetectorFocus: panelCommon.handleFocusDetectorFocus, handleStartTimePickerChange,
|
|
@@ -183,6 +183,8 @@ declare function usePanelCommon(props: UsePanelCommonProps): {
|
|
|
183
183
|
calendarLeftPaddingYear: string;
|
|
184
184
|
calendarLeftPaddingQuarter: string;
|
|
185
185
|
calendarLeftPaddingMonthrange: string;
|
|
186
|
+
calendarLeftPaddingQuarterrange: string;
|
|
187
|
+
calendarLeftPaddingYearrange: string;
|
|
186
188
|
calendarRightPaddingDate: string;
|
|
187
189
|
calendarRightPaddingDatetime: string;
|
|
188
190
|
calendarRightPaddingDaterange: string;
|
|
@@ -191,6 +193,8 @@ declare function usePanelCommon(props: UsePanelCommonProps): {
|
|
|
191
193
|
calendarRightPaddingYear: string;
|
|
192
194
|
calendarRightPaddingQuarter: string;
|
|
193
195
|
calendarRightPaddingMonthrange: string;
|
|
196
|
+
calendarRightPaddingQuarterrange: string;
|
|
197
|
+
calendarRightPaddingYearrange: string;
|
|
194
198
|
};
|
|
195
199
|
peers: {
|
|
196
200
|
Input: import("../../../_mixins").Theme<"Input", {
|
|
@@ -51,7 +51,7 @@ export interface QuarterItem {
|
|
|
51
51
|
*/
|
|
52
52
|
declare function dateArray(monthTs: number, valueTs: number | [number, number] | null, currentTs: number, startDay: 0 | 1 | 2 | 3 | 4 | 5 | 6, strip?: boolean): DateItem[];
|
|
53
53
|
declare function monthArray(yearAnchorTs: number, valueTs: number | null, currentTs: number): MonthItem[];
|
|
54
|
-
declare function quarterArray(
|
|
54
|
+
declare function quarterArray(yearAnchorTs: number, valueTs: number | null, currentTs: number): QuarterItem[];
|
|
55
55
|
declare function yearArray(valueTs: number | null, currentTs: number): YearItem[];
|
|
56
56
|
declare function strictParse(string: string, pattern: string, backup: Date, option: {
|
|
57
57
|
locale: NDateLocale['locale'];
|
|
@@ -145,9 +145,9 @@ function monthArray(yearAnchorTs, valueTs, currentTs) {
|
|
|
145
145
|
}
|
|
146
146
|
return calendarMonths;
|
|
147
147
|
}
|
|
148
|
-
function quarterArray(
|
|
148
|
+
function quarterArray(yearAnchorTs, valueTs, currentTs) {
|
|
149
149
|
const calendarQuarters = [];
|
|
150
|
-
const yearStart = startOfYear(
|
|
150
|
+
const yearStart = startOfYear(yearAnchorTs);
|
|
151
151
|
for (let i = 0; i < 4; i++) {
|
|
152
152
|
calendarQuarters.push(quarterItem(getTime(addQuarters(yearStart, i)), valueTs, currentTs));
|
|
153
153
|
}
|
|
@@ -20,6 +20,8 @@ declare const _default: {
|
|
|
20
20
|
calendarLeftPaddingYear: string;
|
|
21
21
|
calendarLeftPaddingQuarter: string;
|
|
22
22
|
calendarLeftPaddingMonthrange: string;
|
|
23
|
+
calendarLeftPaddingQuarterrange: string;
|
|
24
|
+
calendarLeftPaddingYearrange: string;
|
|
23
25
|
calendarRightPaddingDate: string;
|
|
24
26
|
calendarRightPaddingDatetime: string;
|
|
25
27
|
calendarRightPaddingDaterange: string;
|
|
@@ -28,5 +30,7 @@ declare const _default: {
|
|
|
28
30
|
calendarRightPaddingYear: string;
|
|
29
31
|
calendarRightPaddingQuarter: string;
|
|
30
32
|
calendarRightPaddingMonthrange: string;
|
|
33
|
+
calendarRightPaddingQuarterrange: string;
|
|
34
|
+
calendarRightPaddingYearrange: string;
|
|
31
35
|
};
|
|
32
36
|
export default _default;
|
|
@@ -21,6 +21,8 @@ export default {
|
|
|
21
21
|
calendarLeftPaddingYear: '0',
|
|
22
22
|
calendarLeftPaddingQuarter: '0',
|
|
23
23
|
calendarLeftPaddingMonthrange: '0',
|
|
24
|
+
calendarLeftPaddingQuarterrange: '0',
|
|
25
|
+
calendarLeftPaddingYearrange: '0',
|
|
24
26
|
calendarRightPaddingDate: '6px 12px 4px 12px',
|
|
25
27
|
calendarRightPaddingDatetime: '4px 12px',
|
|
26
28
|
calendarRightPaddingDaterange: '6px 12px 4px 12px',
|
|
@@ -28,5 +30,7 @@ export default {
|
|
|
28
30
|
calendarRightPaddingMonth: '0',
|
|
29
31
|
calendarRightPaddingYear: '0',
|
|
30
32
|
calendarRightPaddingQuarter: '0',
|
|
31
|
-
calendarRightPaddingMonthrange: '0'
|
|
33
|
+
calendarRightPaddingMonthrange: '0',
|
|
34
|
+
calendarRightPaddingQuarterrange: '0',
|
|
35
|
+
calendarRightPaddingYearrange: '0'
|
|
32
36
|
};
|
|
@@ -49,6 +49,8 @@ export declare const self: (vars: ThemeCommonVars) => {
|
|
|
49
49
|
calendarLeftPaddingYear: string;
|
|
50
50
|
calendarLeftPaddingQuarter: string;
|
|
51
51
|
calendarLeftPaddingMonthrange: string;
|
|
52
|
+
calendarLeftPaddingQuarterrange: string;
|
|
53
|
+
calendarLeftPaddingYearrange: string;
|
|
52
54
|
calendarRightPaddingDate: string;
|
|
53
55
|
calendarRightPaddingDatetime: string;
|
|
54
56
|
calendarRightPaddingDaterange: string;
|
|
@@ -57,6 +59,8 @@ export declare const self: (vars: ThemeCommonVars) => {
|
|
|
57
59
|
calendarRightPaddingYear: string;
|
|
58
60
|
calendarRightPaddingQuarter: string;
|
|
59
61
|
calendarRightPaddingMonthrange: string;
|
|
62
|
+
calendarRightPaddingQuarterrange: string;
|
|
63
|
+
calendarRightPaddingYearrange: string;
|
|
60
64
|
};
|
|
61
65
|
export declare type DatePickerThemeVars = ReturnType<typeof self>;
|
|
62
66
|
declare const datePickerLight: import("../../_mixins").Theme<"DatePicker", {
|
|
@@ -109,6 +113,8 @@ declare const datePickerLight: import("../../_mixins").Theme<"DatePicker", {
|
|
|
109
113
|
calendarLeftPaddingYear: string;
|
|
110
114
|
calendarLeftPaddingQuarter: string;
|
|
111
115
|
calendarLeftPaddingMonthrange: string;
|
|
116
|
+
calendarLeftPaddingQuarterrange: string;
|
|
117
|
+
calendarLeftPaddingYearrange: string;
|
|
112
118
|
calendarRightPaddingDate: string;
|
|
113
119
|
calendarRightPaddingDatetime: string;
|
|
114
120
|
calendarRightPaddingDaterange: string;
|
|
@@ -117,6 +123,8 @@ declare const datePickerLight: import("../../_mixins").Theme<"DatePicker", {
|
|
|
117
123
|
calendarRightPaddingYear: string;
|
|
118
124
|
calendarRightPaddingQuarter: string;
|
|
119
125
|
calendarRightPaddingMonthrange: string;
|
|
126
|
+
calendarRightPaddingQuarterrange: string;
|
|
127
|
+
calendarRightPaddingYearrange: string;
|
|
120
128
|
}, {
|
|
121
129
|
Input: import("../../_mixins").Theme<"Input", {
|
|
122
130
|
countTextColor: string;
|
package/es/grid/src/Grid.d.ts
CHANGED
|
@@ -27,6 +27,7 @@ declare const gridProps: {
|
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
29
|
export interface NGridInjection {
|
|
30
|
+
isSsrRef: Ref<boolean>;
|
|
30
31
|
itemStyleRef: Ref<CSSProperties | string | undefined>;
|
|
31
32
|
xGapRef: Ref<string | undefined>;
|
|
32
33
|
overflowRef: Ref<boolean>;
|
|
@@ -57,6 +58,8 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
57
58
|
readonly default: 0;
|
|
58
59
|
};
|
|
59
60
|
}, {
|
|
61
|
+
isSsr: boolean;
|
|
62
|
+
contentEl: Ref<HTMLElement | undefined>;
|
|
60
63
|
mergedClsPrefix: import("vue").ComputedRef<string>;
|
|
61
64
|
style: import("vue").ComputedRef<CSSProperties>;
|
|
62
65
|
isResponsive: import("vue").ComputedRef<boolean>;
|
package/es/grid/src/Grid.js
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { h, defineComponent, computed, provide, toRef, mergeProps, ref, cloneVNode } from 'vue';
|
|
1
|
+
import { h, defineComponent, computed, provide, toRef, mergeProps, ref, cloneVNode, vShow, onMounted } from 'vue';
|
|
2
2
|
import { useBreakpoints, useMemo } from 'vooks';
|
|
3
3
|
import { VResizeObserver } from 'vueuc';
|
|
4
4
|
import { pxfy, parseResponsivePropValue, beforeNextFrameOnce } from 'seemly';
|
|
5
5
|
import { defaultBreakpoints } from '../../config-provider/src/config';
|
|
6
6
|
import { useConfig } from '../../_mixins';
|
|
7
|
-
import { getSlot, flatten } from '../../_utils';
|
|
7
|
+
import { getSlot, flatten, isBrowser, isNodeVShowFalse } from '../../_utils';
|
|
8
8
|
import { defaultSpan, gridInjectionKey } from './config';
|
|
9
9
|
const defaultCols = 24;
|
|
10
|
+
const SSR_ATTR_NAME = '__ssr__';
|
|
10
11
|
const gridProps = {
|
|
11
12
|
responsive: {
|
|
12
13
|
type: [String, Boolean],
|
|
@@ -77,12 +78,27 @@ export default defineComponent({
|
|
|
77
78
|
}
|
|
78
79
|
return undefined;
|
|
79
80
|
});
|
|
81
|
+
// for SSR, fix bug https://github.com/TuSimple/naive-ui/issues/2462
|
|
82
|
+
const isSsrRef = ref(false);
|
|
83
|
+
const contentElRef = ref();
|
|
84
|
+
onMounted(() => {
|
|
85
|
+
const { value: contentEl } = contentElRef;
|
|
86
|
+
if (contentEl) {
|
|
87
|
+
if (contentEl.hasAttribute(SSR_ATTR_NAME)) {
|
|
88
|
+
contentEl.removeAttribute(SSR_ATTR_NAME);
|
|
89
|
+
isSsrRef.value = true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
});
|
|
80
93
|
provide(gridInjectionKey, {
|
|
94
|
+
isSsrRef,
|
|
81
95
|
itemStyleRef: toRef(props, 'itemStyle'),
|
|
82
96
|
xGapRef: responsiveXGapRef,
|
|
83
97
|
overflowRef
|
|
84
98
|
});
|
|
85
99
|
return {
|
|
100
|
+
isSsr: !isBrowser,
|
|
101
|
+
contentEl: contentElRef,
|
|
86
102
|
mergedClsPrefix: mergedClsPrefixRef,
|
|
87
103
|
style: computed(() => {
|
|
88
104
|
return {
|
|
@@ -102,7 +118,7 @@ export default defineComponent({
|
|
|
102
118
|
},
|
|
103
119
|
render() {
|
|
104
120
|
const renderContent = () => {
|
|
105
|
-
var _a, _b, _c, _d, _e, _f;
|
|
121
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
106
122
|
this.overflow = false;
|
|
107
123
|
// render will be called twice when mounted, I can't figure out why
|
|
108
124
|
// 2 jobs will be pushed into job queues with same id, and then be flushed
|
|
@@ -110,11 +126,28 @@ export default defineComponent({
|
|
|
110
126
|
const childrenAndRawSpan = [];
|
|
111
127
|
const { collapsed, collapsedRows, responsiveCols, responsiveQuery } = this;
|
|
112
128
|
rawChildren.forEach((child) => {
|
|
113
|
-
var _a, _b, _c;
|
|
129
|
+
var _a, _b, _c, _d;
|
|
114
130
|
if (((_a = child === null || child === void 0 ? void 0 : child.type) === null || _a === void 0 ? void 0 : _a.__GRID_ITEM__) !== true)
|
|
115
131
|
return;
|
|
132
|
+
if (isNodeVShowFalse(child)) {
|
|
133
|
+
const clonedNode = cloneVNode(child);
|
|
134
|
+
if (clonedNode.props) {
|
|
135
|
+
clonedNode.props.privateShow = false;
|
|
136
|
+
}
|
|
137
|
+
else {
|
|
138
|
+
clonedNode.props = { privateShow: false };
|
|
139
|
+
}
|
|
140
|
+
childrenAndRawSpan.push({
|
|
141
|
+
child: clonedNode,
|
|
142
|
+
rawChildSpan: 0
|
|
143
|
+
});
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
// We don't want v-show to control display, so we need to stripe it
|
|
147
|
+
// here, nor it may mess child's style
|
|
148
|
+
child.dirs = ((_b = child.dirs) === null || _b === void 0 ? void 0 : _b.filter(({ dir }) => dir !== vShow)) || null;
|
|
116
149
|
const clonedChild = cloneVNode(child);
|
|
117
|
-
const rawChildSpan = Number((
|
|
150
|
+
const rawChildSpan = Number((_d = parseResponsivePropValue((_c = clonedChild.props) === null || _c === void 0 ? void 0 : _c.span, responsiveQuery)) !== null && _d !== void 0 ? _d : defaultSpan);
|
|
118
151
|
if (rawChildSpan === 0)
|
|
119
152
|
return;
|
|
120
153
|
childrenAndRawSpan.push({
|
|
@@ -131,7 +164,8 @@ export default defineComponent({
|
|
|
131
164
|
maybeSuffixNode.props.privateSpan = suffixSpan;
|
|
132
165
|
maybeSuffixNode.props.privateColStart =
|
|
133
166
|
responsiveCols + 1 - suffixSpan;
|
|
134
|
-
maybeSuffixNode.props.privateShow =
|
|
167
|
+
maybeSuffixNode.props.privateShow =
|
|
168
|
+
(_e = maybeSuffixNode.props.privateShow) !== null && _e !== void 0 ? _e : true;
|
|
135
169
|
}
|
|
136
170
|
}
|
|
137
171
|
let spanCounter = 0;
|
|
@@ -141,8 +175,9 @@ export default defineComponent({
|
|
|
141
175
|
this.overflow = true;
|
|
142
176
|
}
|
|
143
177
|
if (!done) {
|
|
144
|
-
const childOffset = Number((
|
|
145
|
-
|
|
178
|
+
const childOffset = Number((_g = parseResponsivePropValue((_f = child.props) === null || _f === void 0 ? void 0 : _f.offset, responsiveQuery)) !== null && _g !== void 0 ? _g : 0);
|
|
179
|
+
// it could be 0 sometimes (v-show = false)
|
|
180
|
+
const childSpan = Math.min(rawChildSpan + childOffset, responsiveCols);
|
|
146
181
|
if (!child.props) {
|
|
147
182
|
child.props = {
|
|
148
183
|
privateSpan: childSpan,
|
|
@@ -169,6 +204,7 @@ export default defineComponent({
|
|
|
169
204
|
}
|
|
170
205
|
if (done) {
|
|
171
206
|
if (child.props) {
|
|
207
|
+
// suffix node's privateShow may be true
|
|
172
208
|
if (child.props.privateShow !== true) {
|
|
173
209
|
child.props.privateShow = false;
|
|
174
210
|
}
|
|
@@ -181,8 +217,10 @@ export default defineComponent({
|
|
|
181
217
|
}
|
|
182
218
|
}
|
|
183
219
|
return h('div', mergeProps({
|
|
220
|
+
ref: 'contentEl',
|
|
184
221
|
class: `${this.mergedClsPrefix}-grid`,
|
|
185
|
-
style: this.style
|
|
222
|
+
style: this.style,
|
|
223
|
+
[SSR_ATTR_NAME]: this.isSsr || undefined
|
|
186
224
|
}, this.$attrs), childrenAndRawSpan.map(({ child }) => child));
|
|
187
225
|
};
|
|
188
226
|
return this.isResponsive && this.responsive === 'self' ? (h(VResizeObserver, { onResize: this.handleResize }, {
|
package/es/grid/src/GridItem.js
CHANGED
|
@@ -29,7 +29,7 @@ export default defineComponent({
|
|
|
29
29
|
alias: ['Gi'],
|
|
30
30
|
props: gridItemProps,
|
|
31
31
|
setup() {
|
|
32
|
-
const { xGapRef, itemStyleRef, overflowRef
|
|
32
|
+
const { isSsrRef, xGapRef, itemStyleRef, overflowRef
|
|
33
33
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
34
34
|
} = inject(gridInjectionKey);
|
|
35
35
|
const self = getCurrentInstance();
|
|
@@ -37,6 +37,7 @@ export default defineComponent({
|
|
|
37
37
|
overflow: overflowRef,
|
|
38
38
|
itemStyle: itemStyleRef,
|
|
39
39
|
deriveStyle: () => {
|
|
40
|
+
void isSsrRef.value;
|
|
40
41
|
// Here is quite a hack, I hope there is a better way to solve it
|
|
41
42
|
const { privateSpan = defaultSpan, privateShow = true, privateColStart = undefined, privateOffset = 0
|
|
42
43
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
package/es/image/src/Image.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { PropType, ImgHTMLAttributes } from 'vue';
|
|
2
2
|
import type { ExtractPublicPropTypes } from '../../_utils';
|
|
3
|
+
import type { IntersectionObserverOptions } from './utils';
|
|
3
4
|
export interface ImageInst {
|
|
4
5
|
click: () => void;
|
|
5
6
|
}
|
|
@@ -99,6 +100,8 @@ declare const imageProps: {
|
|
|
99
100
|
alt: StringConstructor;
|
|
100
101
|
height: PropType<string | number>;
|
|
101
102
|
imgProps: PropType<ImgHTMLAttributes>;
|
|
103
|
+
lazy: BooleanConstructor;
|
|
104
|
+
intersectionObserverOptions: PropType<IntersectionObserverOptions>;
|
|
102
105
|
objectFit: {
|
|
103
106
|
type: PropType<"fill" | "none" | "contain" | "cover" | "scale-down">;
|
|
104
107
|
default: string;
|
|
@@ -209,6 +212,8 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
209
212
|
alt: StringConstructor;
|
|
210
213
|
height: PropType<string | number>;
|
|
211
214
|
imgProps: PropType<ImgHTMLAttributes>;
|
|
215
|
+
lazy: BooleanConstructor;
|
|
216
|
+
intersectionObserverOptions: PropType<IntersectionObserverOptions>;
|
|
212
217
|
objectFit: {
|
|
213
218
|
type: PropType<"fill" | "none" | "contain" | "cover" | "scale-down">;
|
|
214
219
|
default: string;
|
|
@@ -233,6 +238,8 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
233
238
|
imageRef: import("vue").Ref<HTMLImageElement | null>;
|
|
234
239
|
imgProps: import("vue").Ref<ImgHTMLAttributes | undefined>;
|
|
235
240
|
showError: import("vue").Ref<boolean>;
|
|
241
|
+
shouldStartLoading: import("vue").Ref<boolean>;
|
|
242
|
+
loaded: import("vue").Ref<boolean>;
|
|
236
243
|
mergedOnError: (e: Event) => void;
|
|
237
244
|
mergedOnLoad: (e: Event) => void;
|
|
238
245
|
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, Record<string, any>, string, import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -331,6 +338,8 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
331
338
|
alt: StringConstructor;
|
|
332
339
|
height: PropType<string | number>;
|
|
333
340
|
imgProps: PropType<ImgHTMLAttributes>;
|
|
341
|
+
lazy: BooleanConstructor;
|
|
342
|
+
intersectionObserverOptions: PropType<IntersectionObserverOptions>;
|
|
334
343
|
objectFit: {
|
|
335
344
|
type: PropType<"fill" | "none" | "contain" | "cover" | "scale-down">;
|
|
336
345
|
default: string;
|
|
@@ -344,6 +353,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
344
353
|
onError: PropType<(e: Event) => void>;
|
|
345
354
|
onLoad: PropType<(e: Event) => void>;
|
|
346
355
|
}>>, {
|
|
356
|
+
lazy: boolean;
|
|
347
357
|
objectFit: "fill" | "none" | "contain" | "cover" | "scale-down";
|
|
348
358
|
showToolbar: boolean;
|
|
349
359
|
showToolbarTooltip: boolean;
|
package/es/image/src/Image.js
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { defineComponent, h, inject, ref, toRef, watchEffect, onMounted } from 'vue';
|
|
1
|
+
import { defineComponent, h, inject, ref, toRef, watchEffect, onMounted, onBeforeUnmount } from 'vue';
|
|
2
2
|
import NImagePreview from './ImagePreview';
|
|
3
3
|
import { imageGroupInjectionKey } from './ImageGroup';
|
|
4
4
|
import { useConfig } from '../../_mixins';
|
|
5
5
|
import { imagePreviewSharedProps } from './interface';
|
|
6
|
-
|
|
6
|
+
import { observeIntersection } from './utils';
|
|
7
|
+
const imageProps = Object.assign({ alt: String, height: [String, Number], imgProps: Object, lazy: Boolean, intersectionObserverOptions: Object, objectFit: {
|
|
7
8
|
type: String,
|
|
8
9
|
default: 'fill'
|
|
9
10
|
}, previewSrc: String, fallbackSrc: String, width: [String, Number], src: String, previewDisabled: Boolean, loadDescription: String, onError: Function, onLoad: Function }, imagePreviewSharedProps);
|
|
@@ -37,18 +38,36 @@ export default defineComponent({
|
|
|
37
38
|
previewInst.toggleShow();
|
|
38
39
|
}
|
|
39
40
|
};
|
|
41
|
+
const shouldStartLoadingRef = ref(!props.lazy);
|
|
40
42
|
onMounted(() => {
|
|
41
43
|
var _a;
|
|
42
44
|
(_a = imageRef.value) === null || _a === void 0 ? void 0 : _a.setAttribute('data-group-id', (imageGroupHandle === null || imageGroupHandle === void 0 ? void 0 : imageGroupHandle.groupId) || '');
|
|
43
45
|
});
|
|
46
|
+
onMounted(() => {
|
|
47
|
+
let unobserve;
|
|
48
|
+
const stopWatchHandle = watchEffect(() => {
|
|
49
|
+
unobserve === null || unobserve === void 0 ? void 0 : unobserve();
|
|
50
|
+
unobserve = undefined;
|
|
51
|
+
if (props.lazy) {
|
|
52
|
+
unobserve = observeIntersection(imageRef.value, props.intersectionObserverOptions, shouldStartLoadingRef);
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
onBeforeUnmount(() => {
|
|
56
|
+
stopWatchHandle();
|
|
57
|
+
unobserve === null || unobserve === void 0 ? void 0 : unobserve();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
44
60
|
watchEffect(() => {
|
|
45
61
|
var _a;
|
|
46
62
|
void props.src;
|
|
47
63
|
void ((_a = props.imgProps) === null || _a === void 0 ? void 0 : _a.src);
|
|
48
64
|
showErrorRef.value = false;
|
|
49
65
|
});
|
|
66
|
+
const loadedRef = ref(false);
|
|
50
67
|
return Object.assign({ mergedClsPrefix: mergedClsPrefixRef, groupId: imageGroupHandle === null || imageGroupHandle === void 0 ? void 0 : imageGroupHandle.groupId, previewInstRef,
|
|
51
|
-
imageRef, imgProps: imgPropsRef, showError: showErrorRef, mergedOnError: (e) => {
|
|
68
|
+
imageRef, imgProps: imgPropsRef, showError: showErrorRef, shouldStartLoading: shouldStartLoadingRef, loaded: loadedRef, mergedOnError: (e) => {
|
|
69
|
+
if (!shouldStartLoadingRef.value)
|
|
70
|
+
return;
|
|
52
71
|
showErrorRef.value = true;
|
|
53
72
|
const { onError, imgProps: { onError: imgPropsOnError } = {} } = props;
|
|
54
73
|
onError === null || onError === void 0 ? void 0 : onError(e);
|
|
@@ -57,18 +76,33 @@ export default defineComponent({
|
|
|
57
76
|
const { onLoad, imgProps: { onLoad: imgPropsOnLoad } = {} } = props;
|
|
58
77
|
onLoad === null || onLoad === void 0 ? void 0 : onLoad(e);
|
|
59
78
|
imgPropsOnLoad === null || imgPropsOnLoad === void 0 ? void 0 : imgPropsOnLoad(e);
|
|
79
|
+
loadedRef.value = true;
|
|
60
80
|
} }, exposedMethods);
|
|
61
81
|
},
|
|
62
82
|
render() {
|
|
63
|
-
|
|
64
|
-
const
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const { mergedClsPrefix, imgProps = {}, loaded, $attrs } = this;
|
|
85
|
+
const placeholderNode = (_b = (_a = this.$slots).placeholder) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
86
|
+
const imgNode = (h("img", Object.assign({}, imgProps, { class: imgProps.class, ref: "imageRef", width: this.width || imgProps.width, height: this.height || imgProps.height, src: this.showError
|
|
87
|
+
? this.fallbackSrc
|
|
88
|
+
: this.shouldStartLoading
|
|
89
|
+
? this.src || imgProps.src
|
|
90
|
+
: undefined, alt: this.alt || imgProps.alt, "aria-label": this.alt || imgProps.alt, onClick: this.click, onError: this.mergedOnError, onLoad: this.mergedOnLoad, style: [
|
|
91
|
+
imgProps.style || '',
|
|
92
|
+
placeholderNode && !loaded
|
|
93
|
+
? { height: '0', width: '0', visibility: 'hidden' }
|
|
94
|
+
: '',
|
|
95
|
+
{ objectFit: this.objectFit }
|
|
96
|
+
], "data-error": this.showError, "data-preview-src": this.previewSrc || this.src })));
|
|
65
97
|
return (h("div", Object.assign({}, $attrs, { role: "none", class: [
|
|
66
98
|
$attrs.class,
|
|
67
99
|
`${mergedClsPrefix}-image`,
|
|
68
100
|
(this.previewDisabled || this.showError) &&
|
|
69
101
|
`${mergedClsPrefix}-image--preview-disabled`
|
|
70
|
-
] }),
|
|
71
|
-
|
|
72
|
-
|
|
102
|
+
] }),
|
|
103
|
+
this.groupId ? (imgNode) : (h(NImagePreview, { theme: this.theme, themeOverrides: this.themeOverrides, clsPrefix: mergedClsPrefix, ref: "previewInstRef", showToolbar: this.showToolbar, showToolbarTooltip: this.showToolbarTooltip }, {
|
|
104
|
+
default: () => imgNode
|
|
105
|
+
})),
|
|
106
|
+
!loaded && placeholderNode));
|
|
73
107
|
}
|
|
74
108
|
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Ref } from 'vue';
|
|
2
|
+
export declare type IntersectionObserverOptions = Omit<IntersectionObserverInit, 'root'> & {
|
|
3
|
+
root?: Element | Document | null | string;
|
|
4
|
+
};
|
|
5
|
+
export declare const resolveOptionsAndHash: (options?: IntersectionObserverOptions | undefined) => {
|
|
6
|
+
hash: string;
|
|
7
|
+
options: Omit<IntersectionObserverInit, "root"> & {
|
|
8
|
+
root: Element | Document;
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export declare const observeIntersection: (el: HTMLImageElement | null, options: IntersectionObserverOptions | undefined, shouldStartLoadingRef: Ref<boolean>) => () => void;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
export const resolveOptionsAndHash = (options = {}) => {
|
|
2
|
+
var _a;
|
|
3
|
+
const { root = null } = options;
|
|
4
|
+
return {
|
|
5
|
+
hash: `${options.rootMargin || '0px 0px 0px 0px'}-${Array.isArray(options.threshold)
|
|
6
|
+
? options.threshold.join(',')
|
|
7
|
+
: (_a = options.threshold) !== null && _a !== void 0 ? _a : '0'}`,
|
|
8
|
+
options: Object.assign(Object.assign({}, options), { root: (typeof root === 'string' ? document.querySelector(root) : root) ||
|
|
9
|
+
document.documentElement })
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
// root -> options -> [observer, elements]
|
|
13
|
+
const observers = new WeakMap();
|
|
14
|
+
const unobserveHandleMap = new WeakMap();
|
|
15
|
+
const shouldStartLoadingRefMap = new WeakMap();
|
|
16
|
+
export const observeIntersection = (el, options, shouldStartLoadingRef) => {
|
|
17
|
+
if (!el)
|
|
18
|
+
return () => { };
|
|
19
|
+
const resolvedOptionsAndHash = resolveOptionsAndHash(options);
|
|
20
|
+
const { root } = resolvedOptionsAndHash.options;
|
|
21
|
+
let rootObservers;
|
|
22
|
+
const _rootObservers = observers.get(root);
|
|
23
|
+
if (_rootObservers) {
|
|
24
|
+
rootObservers = _rootObservers;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
rootObservers = new Map();
|
|
28
|
+
observers.set(root, rootObservers);
|
|
29
|
+
}
|
|
30
|
+
let observer;
|
|
31
|
+
let observerAndObservedElements;
|
|
32
|
+
if (rootObservers.has(resolvedOptionsAndHash.hash)) {
|
|
33
|
+
observerAndObservedElements =
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
|
+
rootObservers.get(resolvedOptionsAndHash.hash);
|
|
36
|
+
if (!observerAndObservedElements[1].has(el)) {
|
|
37
|
+
observer = observerAndObservedElements[0];
|
|
38
|
+
observerAndObservedElements[1].add(el);
|
|
39
|
+
observer.observe(el);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
observer = new IntersectionObserver((entries) => {
|
|
44
|
+
entries.forEach((entry) => {
|
|
45
|
+
if (entry.isIntersecting) {
|
|
46
|
+
const _unobserve = unobserveHandleMap.get(entry.target);
|
|
47
|
+
const _shouldStartLoadingRef = shouldStartLoadingRefMap.get(entry.target);
|
|
48
|
+
if (_unobserve)
|
|
49
|
+
_unobserve();
|
|
50
|
+
if (_shouldStartLoadingRef) {
|
|
51
|
+
_shouldStartLoadingRef.value = true;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
}, resolvedOptionsAndHash.options);
|
|
56
|
+
observer.observe(el);
|
|
57
|
+
observerAndObservedElements = [observer, new Set([el])];
|
|
58
|
+
rootObservers.set(resolvedOptionsAndHash.hash, observerAndObservedElements);
|
|
59
|
+
}
|
|
60
|
+
let unobservered = false;
|
|
61
|
+
const unobserve = () => {
|
|
62
|
+
if (unobservered)
|
|
63
|
+
return;
|
|
64
|
+
unobserveHandleMap.delete(el);
|
|
65
|
+
shouldStartLoadingRefMap.delete(el);
|
|
66
|
+
unobservered = true;
|
|
67
|
+
if (observerAndObservedElements[1].has(el)) {
|
|
68
|
+
observerAndObservedElements[0].unobserve(el);
|
|
69
|
+
observerAndObservedElements[1].delete(el);
|
|
70
|
+
}
|
|
71
|
+
if (observerAndObservedElements[1].size <= 0) {
|
|
72
|
+
rootObservers.delete(resolvedOptionsAndHash.hash);
|
|
73
|
+
}
|
|
74
|
+
if (!rootObservers.size) {
|
|
75
|
+
observers.delete(root);
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
unobserveHandleMap.set(el, unobserve);
|
|
79
|
+
shouldStartLoadingRefMap.set(el, shouldStartLoadingRef);
|
|
80
|
+
return unobserve;
|
|
81
|
+
};
|
|
@@ -19,6 +19,8 @@ export default cB('input-group-label', `
|
|
|
19
19
|
font-size: var(--n-font-size);
|
|
20
20
|
line-height: var(--n-height);
|
|
21
21
|
height: var(--n-height);
|
|
22
|
+
flex-shrink: 0;
|
|
23
|
+
white-space: nowrap;
|
|
22
24
|
transition:
|
|
23
25
|
color .3s var(--n-bezier),
|
|
24
26
|
background-color .3s var(--n-bezier),
|