@formicoidea/labre-core 1.1.0 → 2.0.0
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/architecture/code.c4 +37 -34
- package/architecture/likec4.config.json +3 -3
- package/dist/_pkgs/affine-block-surface/extensions/reading-toolbar.js +12 -12
- package/dist/_pkgs/affine-components/context-menu/menu-renderer.d.ts +3 -1
- package/dist/_pkgs/affine-components/context-menu/menu-renderer.js +9 -1
- package/dist/_pkgs/affine-components/context-menu/menu.d.ts +7 -0
- package/dist/_pkgs/affine-components/context-menu/menu.js +5 -0
- package/dist/_pkgs/affine-components/context-menu/sub-menu.d.ts +16 -1
- package/dist/_pkgs/affine-components/context-menu/sub-menu.js +32 -5
- package/dist/_pkgs/affine-components/highlight-dropdown-menu/highlight-duotone-icon.js +8 -8
- package/dist/_pkgs/affine-components/highlight-dropdown-menu/text-duotone-icon.js +11 -11
- package/dist/_pkgs/affine-database-block/configs/slash-menu.js +14 -6
- package/dist/_pkgs/affine-database-block/database-block-styles.js +4 -3
- package/dist/_pkgs/affine-database-block/database-block.js +6 -18
- package/dist/_pkgs/affine-database-block/database-dnd-preview-block.js +5 -1
- package/dist/_pkgs/affine-database-block/detail-panel/block-renderer.js +5 -2
- package/dist/_pkgs/affine-database-block/detail-panel/note-renderer.js +3 -2
- package/dist/_pkgs/affine-database-block/external-data-source.d.ts +10 -0
- package/dist/_pkgs/affine-database-block/external-data-source.js +24 -0
- package/dist/_pkgs/affine-database-block/properties/created-time/define.js +3 -1
- package/dist/_pkgs/affine-database-block/properties/link/cell-renderer.js +3 -2
- package/dist/_pkgs/affine-database-block/properties/link/define.js +3 -1
- package/dist/_pkgs/affine-database-block/properties/rich-text/define.js +3 -1
- package/dist/_pkgs/affine-database-block/properties/text/hosted.js +1 -0
- package/dist/_pkgs/affine-database-block/properties/title/define.js +3 -1
- package/dist/_pkgs/affine-database-block/properties/title/hosted.js +1 -0
- package/dist/_pkgs/affine-database-block/service/new-row-menu.d.ts +1 -1
- package/dist/_pkgs/affine-database-block/service/new-row-menu.js +1 -1
- package/dist/_pkgs/affine-database-block/translations.d.ts +11 -0
- package/dist/_pkgs/affine-database-block/translations.js +57 -0
- package/dist/_pkgs/affine-database-block/views/index.d.ts +7 -9
- package/dist/_pkgs/affine-database-block/views/index.js +7 -10
- package/dist/_pkgs/affine-database-engine/core/common/properties.js +7 -7
- package/dist/_pkgs/affine-database-engine/core/common/property-menu.d.ts +18 -2
- package/dist/_pkgs/affine-database-engine/core/common/property-menu.js +78 -27
- package/dist/_pkgs/affine-database-engine/core/data-source/base.d.ts +11 -0
- package/dist/_pkgs/affine-database-engine/core/data-source/base.js +3 -0
- package/dist/_pkgs/affine-database-engine/core/detail/detail.js +8 -5
- package/dist/_pkgs/affine-database-engine/core/detail/field.js +14 -7
- package/dist/_pkgs/affine-database-engine/core/filter/add-filter.js +4 -2
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/boolean.js +7 -4
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/create.d.ts +9 -1
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/create.js +2 -0
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/date.js +7 -4
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/multi-tag.js +17 -8
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/number.js +6 -6
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/string.js +19 -12
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/tag.js +9 -4
- package/dist/_pkgs/affine-database-engine/core/filter/filter-fn/unknown.js +7 -4
- package/dist/_pkgs/affine-database-engine/core/filter/literal/define.js +6 -4
- package/dist/_pkgs/affine-database-engine/core/filter/literal/matcher.d.ts +2 -1
- package/dist/_pkgs/affine-database-engine/core/filter/literal/matcher.js +3 -2
- package/dist/_pkgs/affine-database-engine/core/filter/literal/types.d.ts +4 -1
- package/dist/_pkgs/affine-database-engine/core/filter/literal/types.js +1 -1
- package/dist/_pkgs/affine-database-engine/core/group-by/define.js +11 -9
- package/dist/_pkgs/affine-database-engine/core/group-by/group-title.js +16 -6
- package/dist/_pkgs/affine-database-engine/core/group-by/locate-row.d.ts +16 -0
- package/dist/_pkgs/affine-database-engine/core/group-by/locate-row.js +32 -0
- package/dist/_pkgs/affine-database-engine/core/group-by/renderer/date-group.js +10 -3
- package/dist/_pkgs/affine-database-engine/core/group-by/setting.d.ts +2 -0
- package/dist/_pkgs/affine-database-engine/core/group-by/setting.js +40 -28
- package/dist/_pkgs/affine-database-engine/core/group-by/trait.d.ts +3 -0
- package/dist/_pkgs/affine-database-engine/core/group-by/trait.js +8 -0
- package/dist/_pkgs/affine-database-engine/core/group-by/types.d.ts +3 -1
- package/dist/_pkgs/affine-database-engine/core/group-by/types.js +1 -1
- package/dist/_pkgs/affine-database-engine/core/property/types.d.ts +7 -0
- package/dist/_pkgs/affine-database-engine/core/property/types.js +1 -1
- package/dist/_pkgs/affine-database-engine/core/sort/add-sort.js +3 -1
- package/dist/_pkgs/affine-database-engine/core/statistics/any.js +43 -21
- package/dist/_pkgs/affine-database-engine/core/statistics/checkbox.js +29 -14
- package/dist/_pkgs/affine-database-engine/core/statistics/number.js +54 -31
- package/dist/_pkgs/affine-database-engine/core/statistics/types.d.ts +8 -0
- package/dist/_pkgs/affine-database-engine/core/statistics/types.js +2 -1
- package/dist/_pkgs/affine-database-engine/core/utils/wording.d.ts +20 -1
- package/dist/_pkgs/affine-database-engine/core/utils/wording.js +24 -0
- package/dist/_pkgs/affine-database-engine/core/view-manager/property.d.ts +7 -0
- package/dist/_pkgs/affine-database-engine/core/view-manager/property.js +29 -5
- package/dist/_pkgs/affine-database-engine/core/view-manager/single-view.d.ts +14 -0
- package/dist/_pkgs/affine-database-engine/core/view-manager/single-view.js +11 -0
- package/dist/_pkgs/affine-database-engine/property-presets/checkbox/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/date/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/multi-select/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/number/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/number/utils/formats.d.ts +3 -0
- package/dist/_pkgs/affine-database-engine/property-presets/number/utils/formats.js +56 -9
- package/dist/_pkgs/affine-database-engine/property-presets/progress/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/select/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/property-presets/text/define.js +3 -1
- package/dist/_pkgs/affine-database-engine/translations.d.ts +133 -5
- package/dist/_pkgs/affine-database-engine/translations.js +625 -9
- package/dist/_pkgs/affine-database-engine/view-presets/convert.js +0 -28
- package/dist/_pkgs/affine-database-engine/view-presets/effect.js +0 -2
- package/dist/_pkgs/affine-database-engine/view-presets/flat/flat-converts.js +2 -4
- package/dist/_pkgs/affine-database-engine/view-presets/flat/flat-view-ui.d.ts +57 -0
- package/dist/_pkgs/affine-database-engine/view-presets/flat/flat-view-ui.js +113 -4
- package/dist/_pkgs/affine-database-engine/view-presets/gallery/gallery-view.js +2 -1
- package/dist/_pkgs/affine-database-engine/view-presets/index.d.ts +0 -2
- package/dist/_pkgs/affine-database-engine/view-presets/index.js +0 -3
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/kanban-view-manager.js +2 -0
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/mobile/group.js +7 -5
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/mobile/kanban-view-ui-logic.d.ts +5 -0
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/mobile/kanban-view-ui-logic.js +25 -3
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/mobile/menu.js +12 -6
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/controller/selection.d.ts +8 -0
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/controller/selection.js +35 -12
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/group.js +7 -5
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/header.js +5 -1
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/kanban-view-ui-logic.d.ts +5 -0
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/kanban-view-ui-logic.js +8 -4
- package/dist/_pkgs/affine-database-engine/view-presets/kanban/pc/menu.js +12 -6
- package/dist/_pkgs/affine-database-engine/view-presets/list/list-view.js +2 -1
- package/dist/_pkgs/affine-database-engine/view-presets/table/mobile/column-header.js +6 -4
- package/dist/_pkgs/affine-database-engine/view-presets/table/mobile/group.js +6 -5
- package/dist/_pkgs/affine-database-engine/view-presets/table/mobile/header.js +2 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/mobile/table-view-ui-logic.d.ts +4 -3
- package/dist/_pkgs/affine-database-engine/view-presets/table/mobile/table-view-ui-logic.js +29 -5
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/controller/clipboard.js +6 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/controller/selection.js +2 -0
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/group.js +6 -5
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/header/column-header.js +11 -7
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/header/database-header-column.js +16 -12
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/header/number-format-bar.js +4 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/menu.js +9 -6
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/table-view-ui-logic.d.ts +8 -1
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc/table-view-ui-logic.js +29 -7
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/controller/clipboard.js +6 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/controller/selection.js +2 -0
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/bottom/group-footer.js +5 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/bottom/stats/column-stats-column.d.ts +1 -1
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/bottom/stats/column-stats-column.js +14 -6
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/top/group-header.js +5 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/top/group-title.js +5 -3
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/top/header/column-header.js +17 -10
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/top/header/number-format-bar.js +4 -2
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/group/top/header/single-column-header.js +20 -14
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/row/menu.js +9 -6
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/table-view-ui-logic.d.ts +6 -1
- package/dist/_pkgs/affine-database-engine/view-presets/table/pc-virtual/table-view-ui-logic.js +30 -3
- package/dist/_pkgs/affine-database-engine/view-presets/table/stats/column-stats-column.d.ts +1 -1
- package/dist/_pkgs/affine-database-engine/view-presets/table/stats/column-stats-column.js +14 -6
- package/dist/_pkgs/affine-database-engine/view-presets/table/table-view-manager.js +2 -0
- package/dist/_pkgs/affine-database-engine/widget-presets/quick-setting-bar/filter/condition-view.d.ts +2 -0
- package/dist/_pkgs/affine-database-engine/widget-presets/quick-setting-bar/filter/condition-view.js +13 -6
- package/dist/_pkgs/affine-database-engine/widget-presets/quick-setting-bar/filter/group-panel-view.js +20 -13
- package/dist/_pkgs/affine-database-engine/widget-presets/quick-setting-bar/filter/root-panel-view.js +10 -5
- package/dist/_pkgs/affine-database-engine/widget-presets/quick-setting-bar/sort/root-panel.js +8 -5
- package/dist/_pkgs/affine-database-engine/widget-presets/tools/presets/search/search.js +2 -2
- package/dist/_pkgs/affine-database-engine/widget-presets/tools/presets/table-add-row/add-row.d.ts +6 -0
- package/dist/_pkgs/affine-database-engine/widget-presets/tools/presets/table-add-row/add-row.js +49 -4
- package/dist/_pkgs/affine-database-engine/widget-presets/tools/presets/view-options/view-settings.d.ts +3 -3
- package/dist/_pkgs/affine-database-engine/widget-presets/tools/presets/view-options/view-settings.js +3 -3
- package/dist/_pkgs/affine-database-engine/widget-presets/views-bar/views-view.js +5 -0
- package/dist/_pkgs/affine-database-view-block/configs/slash-menu.js +6 -3
- package/dist/_pkgs/affine-database-view-block/data-view-block.js +5 -4
- package/dist/_pkgs/affine-fragment-doc-title/doc-title.d.ts +3 -2
- package/dist/_pkgs/affine-fragment-doc-title/doc-title.js +3 -2
- package/dist/_pkgs/affine-shared/services/data-source-picker-service.d.ts +31 -0
- package/dist/_pkgs/affine-widget-edgeless-zoom-toolbar/index.js +26 -26
- package/dist/_pkgs/affine-widget-keyboard-toolbar/icons.js +98 -98
- package/dist/_pkgs/affine-widget-page-dragging-area/index.js +10 -10
- package/dist/_pkgs/affine-widget-viewport-overlay/index.js +13 -13
- package/package.json +1 -1
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/calendar-view-manager.d.ts +0 -70
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/calendar-view-manager.js +0 -449
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/define.d.ts +0 -10
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/define.js +0 -29
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/effect.d.ts +0 -1
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/effect.js +0 -4
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/index.d.ts +0 -6
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/index.js +0 -6
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/layout.d.ts +0 -37
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/layout.js +0 -138
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/actions.d.ts +0 -7
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/actions.js +0 -64
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/dnd.d.ts +0 -32
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/dnd.js +0 -159
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/effect.d.ts +0 -1
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/effect.js +0 -7
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/hit-test.d.ts +0 -1
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/hit-test.js +0 -28
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/styles.d.ts +0 -1
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/styles.js +0 -707
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/view.d.ts +0 -89
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/pc/view.js +0 -849
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/renderer.d.ts +0 -2
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/renderer.js +0 -8
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/source.d.ts +0 -8
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/source.js +0 -3
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/types.d.ts +0 -79
- package/dist/_pkgs/affine-database-engine/view-presets/calendar/types.js +0 -1
|
@@ -1,849 +0,0 @@
|
|
|
1
|
-
import { menu, popFilterableSimpleMenu, popupTargetFromElement, } from '../../../../affine-components/context-menu/index.js';
|
|
2
|
-
import { ArrowLeftSmallIcon, ArrowRightSmallIcon, CloseIcon, DateTimeIcon, IntegrationsIcon, LinkedPageIcon, PlusIcon, TodayIcon, } from '@blocksuite/icons/lit';
|
|
3
|
-
import { html, nothing } from 'lit';
|
|
4
|
-
import { ref } from 'lit/directives/ref.js';
|
|
5
|
-
import { repeat } from 'lit/directives/repeat.js';
|
|
6
|
-
import { createUniComponentFromWebComponent, renderUniLit, } from '../../../core/index.js';
|
|
7
|
-
import { DataViewUIBase, DataViewUILogicBase, } from '../../../core/view/data-view-base.js';
|
|
8
|
-
import { createCalendarMonthLayout, getCalendarDayContentSlots, getCalendarDaySegmentSlots, getCalendarVisibleMonthRange, } from '../layout.js';
|
|
9
|
-
import { openCalendarEntry } from './actions.js';
|
|
10
|
-
import { CalendarDnd } from './dnd.js';
|
|
11
|
-
import { getCalendarDateFromPoint } from './hit-test.js';
|
|
12
|
-
import { calendarViewStyles } from './styles.js';
|
|
13
|
-
const dateFormatter = new Intl.DateTimeFormat(undefined, { day: 'numeric' });
|
|
14
|
-
const monthFormatter = new Intl.DateTimeFormat(undefined, {
|
|
15
|
-
month: 'long',
|
|
16
|
-
year: 'numeric',
|
|
17
|
-
});
|
|
18
|
-
const weekdayFormatter = new Intl.DateTimeFormat(undefined, {
|
|
19
|
-
weekday: 'short',
|
|
20
|
-
});
|
|
21
|
-
const startOfDay = (time) => {
|
|
22
|
-
const date = time instanceof Date ? time : new Date(time);
|
|
23
|
-
return new Date(date.getFullYear(), date.getMonth(), date.getDate()).getTime();
|
|
24
|
-
};
|
|
25
|
-
const getDefaultCreateDate = (month) => {
|
|
26
|
-
const today = startOfDay(Date.now());
|
|
27
|
-
const monthDate = new Date(month);
|
|
28
|
-
const todayDate = new Date(today);
|
|
29
|
-
if (monthDate.getFullYear() === todayDate.getFullYear() &&
|
|
30
|
-
monthDate.getMonth() === todayDate.getMonth()) {
|
|
31
|
-
return today;
|
|
32
|
-
}
|
|
33
|
-
return new Date(monthDate.getFullYear(), monthDate.getMonth(), 1).getTime();
|
|
34
|
-
};
|
|
35
|
-
export class CalendarViewUILogic extends DataViewUILogicBase {
|
|
36
|
-
constructor() {
|
|
37
|
-
super(...arguments);
|
|
38
|
-
this.dnd = new CalendarDnd(this.root.config.dnd, {
|
|
39
|
-
getEntry: entryId => this.view.entries$.value.find(entry => entry.id === entryId),
|
|
40
|
-
canDragEntry: () => !this.view.readonly$.value,
|
|
41
|
-
canDrop: entity => this.canDropDndEntity(entity),
|
|
42
|
-
onEntryDragStart: entry => {
|
|
43
|
-
this.interactionState = { type: 'drag', entry };
|
|
44
|
-
this.ui?.requestUpdate();
|
|
45
|
-
},
|
|
46
|
-
onEntryDragEnd: () => {
|
|
47
|
-
this.endInteraction();
|
|
48
|
-
},
|
|
49
|
-
onDropTargetChange: (day, entity) => {
|
|
50
|
-
this.setInteractionTarget(day, entity);
|
|
51
|
-
},
|
|
52
|
-
onDrop: (entity, date) => {
|
|
53
|
-
this.dropDndEntity(entity, date);
|
|
54
|
-
},
|
|
55
|
-
});
|
|
56
|
-
this.suppressNextClick = false;
|
|
57
|
-
this.currentMonth = startOfDay(Date.now());
|
|
58
|
-
this.clearSelection = () => {
|
|
59
|
-
this.setSelection(undefined);
|
|
60
|
-
};
|
|
61
|
-
this.addRow = (position) => {
|
|
62
|
-
if (this.view.readonly$.value)
|
|
63
|
-
return;
|
|
64
|
-
const rowId = this.view.rowAdd(position);
|
|
65
|
-
if (rowId) {
|
|
66
|
-
this.root.openDetailPanel({
|
|
67
|
-
view: this.view,
|
|
68
|
-
rowId,
|
|
69
|
-
});
|
|
70
|
-
}
|
|
71
|
-
return rowId;
|
|
72
|
-
};
|
|
73
|
-
this.focusFirstCell = () => { };
|
|
74
|
-
this.onWheel = (event) => {
|
|
75
|
-
if (event.metaKey || event.ctrlKey) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
const ele = event.currentTarget;
|
|
79
|
-
if (ele instanceof HTMLElement) {
|
|
80
|
-
if (ele.scrollWidth === ele.clientWidth) {
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
event.stopPropagation();
|
|
84
|
-
}
|
|
85
|
-
};
|
|
86
|
-
this.showIndicator = () => false;
|
|
87
|
-
this.hideIndicator = () => { };
|
|
88
|
-
this.moveTo = () => { };
|
|
89
|
-
this.renderer = createUniComponentFromWebComponent(CalendarViewUI);
|
|
90
|
-
}
|
|
91
|
-
getPreviewRange() {
|
|
92
|
-
const state = this.interactionState;
|
|
93
|
-
const target = state?.targetDay;
|
|
94
|
-
if (!state || target === undefined)
|
|
95
|
-
return undefined;
|
|
96
|
-
if (state.type === 'doc') {
|
|
97
|
-
return { start: target, end: target };
|
|
98
|
-
}
|
|
99
|
-
if (state.type === 'drag') {
|
|
100
|
-
const entry = state.entry;
|
|
101
|
-
const duration = entry.endAt !== undefined ? entry.endAt - entry.startAt : 0;
|
|
102
|
-
return { start: target, end: startOfDay(target + duration) };
|
|
103
|
-
}
|
|
104
|
-
const entry = state.entry;
|
|
105
|
-
const entryStart = startOfDay(entry.startAt);
|
|
106
|
-
const entryEnd = entry.endAt !== undefined ? startOfDay(entry.endAt) : entryStart;
|
|
107
|
-
if (state.edge === 'start') {
|
|
108
|
-
return {
|
|
109
|
-
start: Math.min(target, entryEnd),
|
|
110
|
-
end: Math.max(target, entryEnd),
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
return {
|
|
114
|
-
start: Math.min(entryStart, target),
|
|
115
|
-
end: Math.max(entryStart, target),
|
|
116
|
-
};
|
|
117
|
-
}
|
|
118
|
-
isDayInPreview(day) {
|
|
119
|
-
const range = this.getPreviewRange();
|
|
120
|
-
if (!range)
|
|
121
|
-
return false;
|
|
122
|
-
return day >= range.start && day <= range.end;
|
|
123
|
-
}
|
|
124
|
-
isEntryBeingMoved(entryId) {
|
|
125
|
-
const state = this.interactionState;
|
|
126
|
-
return (state !== undefined && state.type !== 'doc' && state.entry.id === entryId);
|
|
127
|
-
}
|
|
128
|
-
attach(ui) {
|
|
129
|
-
this.ui = ui;
|
|
130
|
-
this.loadExternalEntries();
|
|
131
|
-
}
|
|
132
|
-
detach(ui) {
|
|
133
|
-
if (this.ui !== ui)
|
|
134
|
-
return;
|
|
135
|
-
this.cleanupResizeInteraction();
|
|
136
|
-
this.dnd.cleanup();
|
|
137
|
-
this.endInteraction();
|
|
138
|
-
this.ui = undefined;
|
|
139
|
-
}
|
|
140
|
-
moveMonth(offset) {
|
|
141
|
-
const date = new Date(this.currentMonth);
|
|
142
|
-
this.currentMonth = startOfDay(new Date(date.getFullYear(), date.getMonth() + offset, 1));
|
|
143
|
-
this.ui?.requestUpdate();
|
|
144
|
-
this.loadExternalEntries();
|
|
145
|
-
}
|
|
146
|
-
goToday() {
|
|
147
|
-
this.currentMonth = startOfDay(Date.now());
|
|
148
|
-
this.ui?.requestUpdate();
|
|
149
|
-
this.loadExternalEntries();
|
|
150
|
-
}
|
|
151
|
-
isCurrentMonth() {
|
|
152
|
-
const cursor = new Date(this.currentMonth);
|
|
153
|
-
const today = new Date();
|
|
154
|
-
return (cursor.getFullYear() === today.getFullYear() &&
|
|
155
|
-
cursor.getMonth() === today.getMonth());
|
|
156
|
-
}
|
|
157
|
-
createRowOnDate(date) {
|
|
158
|
-
if (this.view.readonly$.value)
|
|
159
|
-
return;
|
|
160
|
-
const rowId = this.view.createRowOnDate(date);
|
|
161
|
-
if (rowId) {
|
|
162
|
-
this.root.openDetailPanel({
|
|
163
|
-
view: this.view,
|
|
164
|
-
rowId,
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
openSetupMenu(target) {
|
|
169
|
-
const items = this.view.dateProperties$.value.map(property => menu.action({
|
|
170
|
-
name: property.name$.value || 'Date',
|
|
171
|
-
select: () => {
|
|
172
|
-
this.view.setDateColumn(property.id);
|
|
173
|
-
},
|
|
174
|
-
}));
|
|
175
|
-
if (!this.view.readonly$.value) {
|
|
176
|
-
items.push(menu.action({
|
|
177
|
-
name: 'Create date property',
|
|
178
|
-
select: () => {
|
|
179
|
-
this.view.createDateColumn();
|
|
180
|
-
},
|
|
181
|
-
}));
|
|
182
|
-
}
|
|
183
|
-
popFilterableSimpleMenu(popupTargetFromElement(target), items);
|
|
184
|
-
}
|
|
185
|
-
getWorkspaceCalendarConfig() {
|
|
186
|
-
return (this.view.data$.value?.sources.workspaceCalendar ?? {
|
|
187
|
-
enabled: true,
|
|
188
|
-
});
|
|
189
|
-
}
|
|
190
|
-
createSourceControlItems() {
|
|
191
|
-
const workspaceCalendar = this.getWorkspaceCalendarConfig();
|
|
192
|
-
const selectedIds = workspaceCalendar.subscriptionIds
|
|
193
|
-
? new Set(workspaceCalendar.subscriptionIds)
|
|
194
|
-
: undefined;
|
|
195
|
-
const hasSubscriptionOptions = this.view.externalSources$.value.some(source => (source.getSubscriptionOptions?.().length ?? 0) > 0);
|
|
196
|
-
const subscriptionItems = this.view.externalSources$.value.flatMap(source => source.getSubscriptionOptions?.().map(subscription => menu.action({
|
|
197
|
-
name: `${selectedIds && !selectedIds.has(subscription.id) ? 'Show' : 'Hide'} ${subscription.name}`,
|
|
198
|
-
closeOnSelect: false,
|
|
199
|
-
select: () => {
|
|
200
|
-
const allIds = source
|
|
201
|
-
.getSubscriptionOptions?.()
|
|
202
|
-
.map(subscription => subscription.id);
|
|
203
|
-
if (!allIds?.length) {
|
|
204
|
-
return;
|
|
205
|
-
}
|
|
206
|
-
const next = new Set(selectedIds ?? allIds);
|
|
207
|
-
if (next.has(subscription.id)) {
|
|
208
|
-
next.delete(subscription.id);
|
|
209
|
-
}
|
|
210
|
-
else {
|
|
211
|
-
next.add(subscription.id);
|
|
212
|
-
}
|
|
213
|
-
this.view.setWorkspaceCalendarSubscriptionIds([...next]);
|
|
214
|
-
this.loadExternalEntries();
|
|
215
|
-
},
|
|
216
|
-
})) ?? []);
|
|
217
|
-
const connectItems = this.view.externalSources$.value.flatMap(source => source.openConnectSettings
|
|
218
|
-
? [
|
|
219
|
-
menu.action({
|
|
220
|
-
name: 'Connect calendar',
|
|
221
|
-
closeOnSelect: false,
|
|
222
|
-
select: () => {
|
|
223
|
-
source.openConnectSettings?.();
|
|
224
|
-
},
|
|
225
|
-
}),
|
|
226
|
-
]
|
|
227
|
-
: []);
|
|
228
|
-
const toggleItems = hasSubscriptionOptions
|
|
229
|
-
? [
|
|
230
|
-
menu.action({
|
|
231
|
-
name: workspaceCalendar.enabled
|
|
232
|
-
? 'Hide workspace calendar'
|
|
233
|
-
: 'Show workspace calendar',
|
|
234
|
-
closeOnSelect: false,
|
|
235
|
-
select: () => {
|
|
236
|
-
this.view.setWorkspaceCalendarEnabled(!workspaceCalendar.enabled);
|
|
237
|
-
this.loadExternalEntries();
|
|
238
|
-
},
|
|
239
|
-
}),
|
|
240
|
-
menu.action({
|
|
241
|
-
name: 'Show all workspace calendars',
|
|
242
|
-
closeOnSelect: false,
|
|
243
|
-
select: () => {
|
|
244
|
-
this.view.setWorkspaceCalendarSubscriptionIds(undefined);
|
|
245
|
-
this.loadExternalEntries();
|
|
246
|
-
},
|
|
247
|
-
}),
|
|
248
|
-
]
|
|
249
|
-
: [];
|
|
250
|
-
return [...toggleItems, ...subscriptionItems, ...connectItems];
|
|
251
|
-
}
|
|
252
|
-
openSourceMenu(target) {
|
|
253
|
-
popFilterableSimpleMenu(popupTargetFromElement(target), this.createSourceControlItems());
|
|
254
|
-
}
|
|
255
|
-
getDatePropertyMenuItems(selectedPropertyId, onSelect, create, options) {
|
|
256
|
-
const closeOnSelect = options?.closeOnSelect;
|
|
257
|
-
const items = [];
|
|
258
|
-
if (options?.includeNone) {
|
|
259
|
-
items.push(menu.action({
|
|
260
|
-
name: 'None',
|
|
261
|
-
isSelected: !selectedPropertyId,
|
|
262
|
-
closeOnSelect,
|
|
263
|
-
select: () => onSelect(undefined),
|
|
264
|
-
}));
|
|
265
|
-
}
|
|
266
|
-
items.push(...this.view.dateProperties$.value.map(property => menu.action({
|
|
267
|
-
name: property.name$.value || 'Date',
|
|
268
|
-
isSelected: property.id === selectedPropertyId,
|
|
269
|
-
closeOnSelect,
|
|
270
|
-
select: () => onSelect(property.id),
|
|
271
|
-
})));
|
|
272
|
-
if (!this.view.readonly$.value && create) {
|
|
273
|
-
items.push(menu.action({
|
|
274
|
-
name: options?.createLabel ?? 'Create date property',
|
|
275
|
-
closeOnSelect,
|
|
276
|
-
select: create,
|
|
277
|
-
}));
|
|
278
|
-
}
|
|
279
|
-
return items;
|
|
280
|
-
}
|
|
281
|
-
getViewOptionsSettingItems(navigateToSubPage, goBack) {
|
|
282
|
-
const selectedStart = this.view.startDateMapping$.value.propertyId;
|
|
283
|
-
const selectedEnd = this.view.endDateMapping$.value.propertyId;
|
|
284
|
-
return [
|
|
285
|
-
menu.group({
|
|
286
|
-
name: 'Date range',
|
|
287
|
-
items: [
|
|
288
|
-
menu.action({
|
|
289
|
-
name: 'Calendar by',
|
|
290
|
-
prefix: TodayIcon(),
|
|
291
|
-
closeOnSelect: false,
|
|
292
|
-
postfix: html `<div
|
|
293
|
-
style="font-size:14px;color:var(--affine-text-secondary-color);"
|
|
294
|
-
>
|
|
295
|
-
${this.view.startDateMapping$.value.status === 'ready'
|
|
296
|
-
? this.view.propertyGetOrCreate(selectedStart ?? '').name$
|
|
297
|
-
.value
|
|
298
|
-
: ''}
|
|
299
|
-
</div>
|
|
300
|
-
${ArrowRightSmallIcon()}`,
|
|
301
|
-
select: () => {
|
|
302
|
-
navigateToSubPage('Calendar by', () => this.getDatePropertyMenuItems(this.view.startDateMapping$.value.propertyId, propertyId => {
|
|
303
|
-
if (propertyId) {
|
|
304
|
-
this.view.setStartDateColumn(propertyId);
|
|
305
|
-
goBack();
|
|
306
|
-
}
|
|
307
|
-
}, () => {
|
|
308
|
-
this.view.createStartDateColumn();
|
|
309
|
-
goBack();
|
|
310
|
-
}, { closeOnSelect: false }));
|
|
311
|
-
},
|
|
312
|
-
}),
|
|
313
|
-
menu.action({
|
|
314
|
-
name: 'End date',
|
|
315
|
-
prefix: DateTimeIcon(),
|
|
316
|
-
closeOnSelect: false,
|
|
317
|
-
postfix: html `<div
|
|
318
|
-
style="font-size:14px;color:var(--affine-text-secondary-color);"
|
|
319
|
-
>
|
|
320
|
-
${selectedEnd
|
|
321
|
-
? this.view.propertyGetOrCreate(selectedEnd).name$.value
|
|
322
|
-
: 'None'}
|
|
323
|
-
</div>
|
|
324
|
-
${ArrowRightSmallIcon()}`,
|
|
325
|
-
select: () => {
|
|
326
|
-
navigateToSubPage('End date', () => this.getDatePropertyMenuItems(this.view.endDateMapping$.value.propertyId, propertyId => {
|
|
327
|
-
this.view.setEndDateColumn(propertyId);
|
|
328
|
-
goBack();
|
|
329
|
-
}, () => {
|
|
330
|
-
this.view.createEndDateColumn();
|
|
331
|
-
goBack();
|
|
332
|
-
}, {
|
|
333
|
-
includeNone: true,
|
|
334
|
-
createLabel: 'Create end date property',
|
|
335
|
-
closeOnSelect: false,
|
|
336
|
-
}));
|
|
337
|
-
},
|
|
338
|
-
}),
|
|
339
|
-
menu.action({
|
|
340
|
-
name: 'External calendars',
|
|
341
|
-
prefix: IntegrationsIcon(),
|
|
342
|
-
closeOnSelect: false,
|
|
343
|
-
postfix: html `${ArrowRightSmallIcon()}`,
|
|
344
|
-
select: () => {
|
|
345
|
-
navigateToSubPage('External calendars', () => this.createSourceControlItems());
|
|
346
|
-
},
|
|
347
|
-
}),
|
|
348
|
-
],
|
|
349
|
-
}),
|
|
350
|
-
];
|
|
351
|
-
}
|
|
352
|
-
openEntry(entry, target) {
|
|
353
|
-
openCalendarEntry(this.root, this.view, entry, target, {
|
|
354
|
-
selectEntry: entryId => {
|
|
355
|
-
this.selectedEntryId = entryId;
|
|
356
|
-
this.ui?.requestUpdate();
|
|
357
|
-
},
|
|
358
|
-
});
|
|
359
|
-
}
|
|
360
|
-
get isInteracting() {
|
|
361
|
-
return this.interactionState !== undefined;
|
|
362
|
-
}
|
|
363
|
-
setInteractionTarget(day, entity) {
|
|
364
|
-
if (day !== undefined && entity?.type === 'doc') {
|
|
365
|
-
const current = this.interactionState;
|
|
366
|
-
if (current?.type === 'doc' &&
|
|
367
|
-
current.docId === entity.docId &&
|
|
368
|
-
current.targetDay === day) {
|
|
369
|
-
return;
|
|
370
|
-
}
|
|
371
|
-
this.interactionState = {
|
|
372
|
-
type: 'doc',
|
|
373
|
-
docId: entity.docId,
|
|
374
|
-
targetDay: day,
|
|
375
|
-
};
|
|
376
|
-
this.ui?.requestUpdate();
|
|
377
|
-
return;
|
|
378
|
-
}
|
|
379
|
-
if (this.interactionState?.type === 'doc') {
|
|
380
|
-
this.interactionState = undefined;
|
|
381
|
-
this.ui?.requestUpdate();
|
|
382
|
-
return;
|
|
383
|
-
}
|
|
384
|
-
if (this.interactionState?.targetDay !== day) {
|
|
385
|
-
if (this.interactionState) {
|
|
386
|
-
this.interactionState = {
|
|
387
|
-
...this.interactionState,
|
|
388
|
-
targetDay: day,
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
this.ui?.requestUpdate();
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
endInteraction() {
|
|
395
|
-
this.interactionState = undefined;
|
|
396
|
-
this.ui?.requestUpdate();
|
|
397
|
-
}
|
|
398
|
-
bindCalendarDropTarget(element) {
|
|
399
|
-
this.dnd.bindRoot(element);
|
|
400
|
-
}
|
|
401
|
-
bindEntryDraggable(key, entry, element) {
|
|
402
|
-
this.dnd.bindEntry(key, entry, element, this.view.readonly$.value);
|
|
403
|
-
}
|
|
404
|
-
canDropDndEntity(entity) {
|
|
405
|
-
if (this.view.readonly$.value) {
|
|
406
|
-
return false;
|
|
407
|
-
}
|
|
408
|
-
if (entity.type === 'calendar-entry') {
|
|
409
|
-
const entry = this.view.entries$.value.find(entry => entry.id === entity.entryId);
|
|
410
|
-
return entry?.kind === 'row';
|
|
411
|
-
}
|
|
412
|
-
if (entity.type === 'doc') {
|
|
413
|
-
return this.view.startDateMapping$.value.status === 'ready';
|
|
414
|
-
}
|
|
415
|
-
return false;
|
|
416
|
-
}
|
|
417
|
-
dropDndEntity(entity, day) {
|
|
418
|
-
try {
|
|
419
|
-
if (entity.type === 'calendar-entry') {
|
|
420
|
-
const entry = this.view.entries$.value.find(entry => entry.id === entity.entryId);
|
|
421
|
-
if (entry?.kind === 'row') {
|
|
422
|
-
this.view.moveRowToDate(entry.rowId, day);
|
|
423
|
-
}
|
|
424
|
-
}
|
|
425
|
-
if (entity.type === 'doc') {
|
|
426
|
-
this.view.createLinkedDocRowOnDate(day, entity.docId);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
finally {
|
|
430
|
-
this.endInteraction();
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
startResize(entry, edge, event) {
|
|
434
|
-
if (entry.kind !== 'row' || !entry.canResizeRange) {
|
|
435
|
-
return;
|
|
436
|
-
}
|
|
437
|
-
event.preventDefault();
|
|
438
|
-
event.stopPropagation();
|
|
439
|
-
this.cleanupResizeInteraction();
|
|
440
|
-
this.interactionState = {
|
|
441
|
-
type: 'resize',
|
|
442
|
-
entry: entry,
|
|
443
|
-
edge,
|
|
444
|
-
};
|
|
445
|
-
this.ui?.requestUpdate();
|
|
446
|
-
const root = event.currentTarget.closest('.calendar-grid');
|
|
447
|
-
const doc = event.currentTarget.ownerDocument;
|
|
448
|
-
const dayFromPointer = (pointerEvent) => {
|
|
449
|
-
if (!root) {
|
|
450
|
-
return;
|
|
451
|
-
}
|
|
452
|
-
return getCalendarDateFromPoint(root, pointerEvent.clientX, pointerEvent.clientY);
|
|
453
|
-
};
|
|
454
|
-
const onPointerMove = (pointerEvent) => {
|
|
455
|
-
this.setInteractionTarget(dayFromPointer(pointerEvent));
|
|
456
|
-
};
|
|
457
|
-
const onPointerUp = (pointerEvent) => {
|
|
458
|
-
cleanup();
|
|
459
|
-
const date = dayFromPointer(pointerEvent);
|
|
460
|
-
if (date !== undefined) {
|
|
461
|
-
this.view.resizeRowRange(entry.rowId, edge, date);
|
|
462
|
-
}
|
|
463
|
-
this.endInteraction();
|
|
464
|
-
// Suppress the click event that the browser fires after pointerup
|
|
465
|
-
// when the pointer is released on top of the entry element.
|
|
466
|
-
this.suppressNextClick = true;
|
|
467
|
-
requestAnimationFrame(() => {
|
|
468
|
-
this.suppressNextClick = false;
|
|
469
|
-
});
|
|
470
|
-
};
|
|
471
|
-
const cleanup = () => {
|
|
472
|
-
doc.removeEventListener('pointermove', onPointerMove);
|
|
473
|
-
doc.removeEventListener('pointerup', onPointerUp);
|
|
474
|
-
if (this.cleanupResize === cleanup) {
|
|
475
|
-
this.cleanupResize = undefined;
|
|
476
|
-
}
|
|
477
|
-
};
|
|
478
|
-
this.cleanupResize = cleanup;
|
|
479
|
-
doc.addEventListener('pointermove', onPointerMove);
|
|
480
|
-
doc.addEventListener('pointerup', onPointerUp);
|
|
481
|
-
}
|
|
482
|
-
cleanupResizeInteraction() {
|
|
483
|
-
this.cleanupResize?.();
|
|
484
|
-
this.cleanupResize = undefined;
|
|
485
|
-
}
|
|
486
|
-
handleEntryClick(entry, target) {
|
|
487
|
-
if (this.suppressNextClick) {
|
|
488
|
-
return;
|
|
489
|
-
}
|
|
490
|
-
this.openEntry(entry, target);
|
|
491
|
-
}
|
|
492
|
-
handleEntryKeydown(entry, event) {
|
|
493
|
-
if (event.key !== 'Enter' && event.key !== ' ') {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
event.preventDefault();
|
|
497
|
-
this.handleEntryClick(entry, event.currentTarget);
|
|
498
|
-
}
|
|
499
|
-
loadExternalEntries() {
|
|
500
|
-
const range = getCalendarVisibleMonthRange(this.currentMonth);
|
|
501
|
-
this.view
|
|
502
|
-
.loadExternalEntries({ from: range.from, to: range.to })
|
|
503
|
-
.catch(() => {
|
|
504
|
-
this.root.config.notification.toast('Failed to load calendar entries');
|
|
505
|
-
});
|
|
506
|
-
}
|
|
507
|
-
}
|
|
508
|
-
export class CalendarViewUI extends DataViewUIBase {
|
|
509
|
-
static { this.styles = calendarViewStyles; }
|
|
510
|
-
connectedCallback() {
|
|
511
|
-
super.connectedCallback();
|
|
512
|
-
this.logic.attach(this);
|
|
513
|
-
this.dataset['testid'] = 'dv-calendar-view';
|
|
514
|
-
}
|
|
515
|
-
disconnectedCallback() {
|
|
516
|
-
this.logic.detach(this);
|
|
517
|
-
super.disconnectedCallback();
|
|
518
|
-
}
|
|
519
|
-
renderEntry(entry, extraStyle = '', segment) {
|
|
520
|
-
const dndKey = segment
|
|
521
|
-
? `${entry.id}:${segment.weekIndex}:${segment.startIndex}`
|
|
522
|
-
: `${entry.id}:day`;
|
|
523
|
-
const colorStyle = entry.kind === 'external' && entry.color
|
|
524
|
-
? `--calendar-external-color:${entry.color};`
|
|
525
|
-
: '';
|
|
526
|
-
const segmentClass = segment
|
|
527
|
-
? `${segment.startsBeforeWeek ? 'continues-left' : ''} ${segment.endsAfterWeek ? 'continues-right' : ''}`
|
|
528
|
-
: '';
|
|
529
|
-
const canResize = entry.kind === 'row' && entry.canResizeRange;
|
|
530
|
-
const showLeftHandle = canResize && segment && !segment.startsBeforeWeek;
|
|
531
|
-
const showRightHandle = canResize && segment && !segment.endsAfterWeek;
|
|
532
|
-
return html `
|
|
533
|
-
<div
|
|
534
|
-
${ref(element => this.logic.bindEntryDraggable(dndKey, entry, element))}
|
|
535
|
-
class="calendar-entry ${entry.kind} ${segmentClass} ${this.logic
|
|
536
|
-
.selectedEntryId === entry.id
|
|
537
|
-
? 'selected'
|
|
538
|
-
: ''}"
|
|
539
|
-
role="button"
|
|
540
|
-
tabindex="0"
|
|
541
|
-
aria-label=${entry.title || 'Untitled'}
|
|
542
|
-
style=${`${colorStyle}${extraStyle}`}
|
|
543
|
-
@click=${(event) => {
|
|
544
|
-
this.logic.handleEntryClick(entry, event.currentTarget);
|
|
545
|
-
}}
|
|
546
|
-
@keydown=${(event) => {
|
|
547
|
-
this.logic.handleEntryKeydown(entry, event);
|
|
548
|
-
}}
|
|
549
|
-
>
|
|
550
|
-
${showLeftHandle
|
|
551
|
-
? html `<span
|
|
552
|
-
class="calendar-resize-handle left"
|
|
553
|
-
@pointerdown=${(event) => this.logic.startResize(entry, 'start', event)}
|
|
554
|
-
></span>`
|
|
555
|
-
: nothing}
|
|
556
|
-
${this.renderEntryTitle(entry)}
|
|
557
|
-
${entry.kind === 'row' && entry.cardProperties.length
|
|
558
|
-
? html `<span class="calendar-entry-properties">
|
|
559
|
-
${entry.cardProperties.map(property => html `<span class="calendar-entry-property"
|
|
560
|
-
>${property.value}</span
|
|
561
|
-
>`)}
|
|
562
|
-
</span>`
|
|
563
|
-
: nothing}
|
|
564
|
-
${showRightHandle
|
|
565
|
-
? html `<span
|
|
566
|
-
class="calendar-resize-handle right"
|
|
567
|
-
@pointerdown=${(event) => this.logic.startResize(entry, 'end', event)}
|
|
568
|
-
></span>`
|
|
569
|
-
: nothing}
|
|
570
|
-
</div>
|
|
571
|
-
`;
|
|
572
|
-
}
|
|
573
|
-
renderEntryTitle(entry) {
|
|
574
|
-
if (entry.kind !== 'row') {
|
|
575
|
-
return html `<span
|
|
576
|
-
class="calendar-entry-title ${entry.title ? '' : 'is-empty'}"
|
|
577
|
-
>${entry.title || 'Untitled'}</span
|
|
578
|
-
>`;
|
|
579
|
-
}
|
|
580
|
-
if (entry.titleSegments?.length) {
|
|
581
|
-
return html `<span class="calendar-entry-title title-segments">
|
|
582
|
-
${entry.titleSegments.map(segment => html `<span
|
|
583
|
-
class="calendar-entry-title-segment ${segment.linkedDoc
|
|
584
|
-
? 'linked-doc-segment'
|
|
585
|
-
: ''}"
|
|
586
|
-
>
|
|
587
|
-
${segment.linkedDoc ? LinkedPageIcon() : nothing}
|
|
588
|
-
${segment.text
|
|
589
|
-
? html `<span class="calendar-entry-title-text"
|
|
590
|
-
>${segment.text}</span
|
|
591
|
-
>`
|
|
592
|
-
: nothing}
|
|
593
|
-
</span>`)}
|
|
594
|
-
</span>`;
|
|
595
|
-
}
|
|
596
|
-
return html `<span
|
|
597
|
-
class="calendar-entry-title ${entry.title ? '' : 'is-empty'}"
|
|
598
|
-
>${entry.title || 'Untitled'}</span
|
|
599
|
-
>`;
|
|
600
|
-
}
|
|
601
|
-
getMovingEntryId() {
|
|
602
|
-
const state = this.logic.interactionState;
|
|
603
|
-
return state?.type !== 'doc' ? state?.entry.id : undefined;
|
|
604
|
-
}
|
|
605
|
-
renderDayPreview(dayDate) {
|
|
606
|
-
const range = this.logic.getPreviewRange();
|
|
607
|
-
if (!range || range.start !== range.end)
|
|
608
|
-
return nothing;
|
|
609
|
-
if (dayDate !== range.start)
|
|
610
|
-
return nothing;
|
|
611
|
-
const state = this.logic.interactionState;
|
|
612
|
-
if (!state)
|
|
613
|
-
return nothing;
|
|
614
|
-
if (state.type === 'doc') {
|
|
615
|
-
return html `<div class="calendar-entry-preview doc">
|
|
616
|
-
${LinkedPageIcon()}
|
|
617
|
-
<span class="calendar-entry-title-text"
|
|
618
|
-
>${this.logic.view.getDocDisplayTitle(state.docId)}</span
|
|
619
|
-
>
|
|
620
|
-
</div>`;
|
|
621
|
-
}
|
|
622
|
-
const title = state.entry.title || 'Untitled';
|
|
623
|
-
return html `<div class="calendar-entry-preview">${title}</div>`;
|
|
624
|
-
}
|
|
625
|
-
getSegmentPreviewLayout(week) {
|
|
626
|
-
const range = this.logic.getPreviewRange();
|
|
627
|
-
if (!range || range.start === range.end)
|
|
628
|
-
return;
|
|
629
|
-
const state = this.logic.interactionState;
|
|
630
|
-
if (!state || state.type === 'doc')
|
|
631
|
-
return;
|
|
632
|
-
const weekStart = week[0]?.date;
|
|
633
|
-
const weekEnd = week[6]?.date;
|
|
634
|
-
if (weekStart === undefined || weekEnd === undefined)
|
|
635
|
-
return;
|
|
636
|
-
if (range.start > weekEnd || range.end < weekStart)
|
|
637
|
-
return;
|
|
638
|
-
const segStart = Math.max(range.start, weekStart);
|
|
639
|
-
const segEnd = Math.min(range.end, weekEnd);
|
|
640
|
-
const sIdx = week.findIndex(d => d.date === segStart);
|
|
641
|
-
const eIdx = week.findIndex(d => d.date === segEnd);
|
|
642
|
-
if (sIdx < 0 || eIdx < 0)
|
|
643
|
-
return;
|
|
644
|
-
const slot = Math.max(0, ...week
|
|
645
|
-
.slice(sIdx, eIdx + 1)
|
|
646
|
-
.map(day => getCalendarDayContentSlots(day, state.entry.id)));
|
|
647
|
-
return {
|
|
648
|
-
sIdx,
|
|
649
|
-
eIdx,
|
|
650
|
-
span: eIdx - sIdx + 1,
|
|
651
|
-
slot,
|
|
652
|
-
continuesLeft: range.start < weekStart,
|
|
653
|
-
continuesRight: range.end > weekEnd,
|
|
654
|
-
title: range.start < weekStart ? '' : state.entry.title || 'Untitled',
|
|
655
|
-
};
|
|
656
|
-
}
|
|
657
|
-
renderPreviewSpacer(day, preview, dayIndex) {
|
|
658
|
-
const movingEntryId = this.getMovingEntryId();
|
|
659
|
-
if (!preview || dayIndex < preview.sIdx || dayIndex > preview.eIdx) {
|
|
660
|
-
return nothing;
|
|
661
|
-
}
|
|
662
|
-
const spacerSlots = preview.slot + 1 - getCalendarDayContentSlots(day, movingEntryId);
|
|
663
|
-
if (spacerSlots <= 0) {
|
|
664
|
-
return nothing;
|
|
665
|
-
}
|
|
666
|
-
return html `<div
|
|
667
|
-
class="calendar-preview-spacer"
|
|
668
|
-
style="height:calc(${spacerSlots} * var(--calendar-entry-slot-height));"
|
|
669
|
-
></div>`;
|
|
670
|
-
}
|
|
671
|
-
renderSegmentPreview(preview) {
|
|
672
|
-
if (!preview)
|
|
673
|
-
return nothing;
|
|
674
|
-
return html `<div
|
|
675
|
-
class="calendar-entry-preview ${preview.continuesLeft
|
|
676
|
-
? 'continues-left'
|
|
677
|
-
: ''} ${preview.continuesRight ? 'continues-right' : ''}"
|
|
678
|
-
style="grid-column:${preview.sIdx +
|
|
679
|
-
1} / span ${preview.span};grid-row:${preview.slot + 1};"
|
|
680
|
-
>
|
|
681
|
-
${preview.title}
|
|
682
|
-
</div>`;
|
|
683
|
-
}
|
|
684
|
-
renderEmptyMonthHint(showHint) {
|
|
685
|
-
if (!showHint) {
|
|
686
|
-
return nothing;
|
|
687
|
-
}
|
|
688
|
-
return html `<div class="calendar-empty-month-hint">
|
|
689
|
-
<div class="calendar-empty-month-hint-copy">
|
|
690
|
-
<span class="calendar-empty-month-hint-title">Nothing here yet</span>
|
|
691
|
-
<span class="calendar-empty-month-hint-body">
|
|
692
|
-
Add a row to any date, it'll appear here on the calendar.
|
|
693
|
-
</span>
|
|
694
|
-
</div>
|
|
695
|
-
<div class="calendar-empty-month-hint-actions">
|
|
696
|
-
${this.logic.view.readonly$.value
|
|
697
|
-
? nothing
|
|
698
|
-
: html `<button
|
|
699
|
-
class="calendar-empty-month-hint-action"
|
|
700
|
-
@click=${() => this.logic.createRowOnDate(getDefaultCreateDate(this.logic.currentMonth))}
|
|
701
|
-
>
|
|
702
|
-
${PlusIcon()}<span>New row</span>
|
|
703
|
-
</button>`}
|
|
704
|
-
<button
|
|
705
|
-
class="calendar-empty-month-hint-close"
|
|
706
|
-
aria-label="Dismiss"
|
|
707
|
-
@click=${() => this.logic.view.dismissEmptyMonthHint()}
|
|
708
|
-
>
|
|
709
|
-
${CloseIcon()}
|
|
710
|
-
</button>
|
|
711
|
-
</div>
|
|
712
|
-
</div>`;
|
|
713
|
-
}
|
|
714
|
-
renderCalendar(skeleton = false) {
|
|
715
|
-
const entries = skeleton ? [] : this.logic.view.entries$.value;
|
|
716
|
-
const layout = createCalendarMonthLayout({
|
|
717
|
-
month: this.logic.currentMonth,
|
|
718
|
-
entries,
|
|
719
|
-
});
|
|
720
|
-
const weekdays = layout.weeks[0] ?? [];
|
|
721
|
-
const today = startOfDay(Date.now());
|
|
722
|
-
const currentMonthEmpty = layout.days
|
|
723
|
-
.filter(day => day.inMonth)
|
|
724
|
-
.every(day => day.entries.length === 0 && day.segments.length === 0);
|
|
725
|
-
const showEmptyMonthHint = currentMonthEmpty &&
|
|
726
|
-
!skeleton &&
|
|
727
|
-
!this.logic.view.emptyMonthHintDismissed$.value;
|
|
728
|
-
return html `
|
|
729
|
-
<div class="calendar-shell">
|
|
730
|
-
<div class="calendar-toolbar">
|
|
731
|
-
<div class="calendar-title">
|
|
732
|
-
${monthFormatter.format(new Date(this.logic.currentMonth))}
|
|
733
|
-
</div>
|
|
734
|
-
<div class="calendar-nav">
|
|
735
|
-
${this.logic.isCurrentMonth()
|
|
736
|
-
? nothing
|
|
737
|
-
: html `<button
|
|
738
|
-
class="calendar-today-button"
|
|
739
|
-
@click=${() => this.logic.goToday()}
|
|
740
|
-
>
|
|
741
|
-
<span>Today</span>
|
|
742
|
-
</button>`}
|
|
743
|
-
<button
|
|
744
|
-
class="calendar-icon-button"
|
|
745
|
-
aria-label="Previous month"
|
|
746
|
-
@click=${() => this.logic.moveMonth(-1)}
|
|
747
|
-
>
|
|
748
|
-
${ArrowLeftSmallIcon()}
|
|
749
|
-
</button>
|
|
750
|
-
<button
|
|
751
|
-
class="calendar-icon-button"
|
|
752
|
-
aria-label="Next month"
|
|
753
|
-
@click=${() => this.logic.moveMonth(1)}
|
|
754
|
-
>
|
|
755
|
-
${ArrowRightSmallIcon()}
|
|
756
|
-
</button>
|
|
757
|
-
</div>
|
|
758
|
-
</div>
|
|
759
|
-
${this.renderEmptyMonthHint(showEmptyMonthHint)}
|
|
760
|
-
<div class="calendar-weekdays">
|
|
761
|
-
${repeat(weekdays, day => day.date, day => html `<div class="calendar-weekday">
|
|
762
|
-
${weekdayFormatter.format(new Date(day.date))}
|
|
763
|
-
</div>`)}
|
|
764
|
-
</div>
|
|
765
|
-
<div
|
|
766
|
-
${ref(element => this.logic.bindCalendarDropTarget(element))}
|
|
767
|
-
class="calendar-grid"
|
|
768
|
-
>
|
|
769
|
-
${repeat(layout.weeks, week => week[0]?.date ?? 0, week => {
|
|
770
|
-
const weekSegments = layout.segments.filter(segment => segment.weekIndex === layout.weeks.indexOf(week));
|
|
771
|
-
const preview = this.getSegmentPreviewLayout(week);
|
|
772
|
-
const movingEntryId = this.getMovingEntryId();
|
|
773
|
-
return html `
|
|
774
|
-
<div class="calendar-week">
|
|
775
|
-
${repeat(week, day => day.date, (day, dayIndex) => {
|
|
776
|
-
const canReserveNewRow = !this.logic.view.readonly$.value && day.inMonth;
|
|
777
|
-
return html `
|
|
778
|
-
<div
|
|
779
|
-
data-date=${day.date}
|
|
780
|
-
class="calendar-day ${day.inMonth
|
|
781
|
-
? ''
|
|
782
|
-
: 'is-outside'} ${day.date === today
|
|
783
|
-
? 'is-today'
|
|
784
|
-
: ''} ${this.logic.isDayInPreview(day.date)
|
|
785
|
-
? 'is-drop-target'
|
|
786
|
-
: ''}"
|
|
787
|
-
style="--calendar-segment-slots:${getCalendarDaySegmentSlots(day, movingEntryId)};"
|
|
788
|
-
>
|
|
789
|
-
<div class="calendar-day-number">
|
|
790
|
-
${dateFormatter.format(new Date(day.date))}
|
|
791
|
-
</div>
|
|
792
|
-
<div class="calendar-day-entries">
|
|
793
|
-
${day.entries
|
|
794
|
-
.filter(e => !this.logic.isEntryBeingMoved(e.id))
|
|
795
|
-
.map(entry => this.renderEntry(entry))}
|
|
796
|
-
${this.renderDayPreview(day.date)}
|
|
797
|
-
${this.renderPreviewSpacer(day, preview, dayIndex)}
|
|
798
|
-
</div>
|
|
799
|
-
${canReserveNewRow
|
|
800
|
-
? html `<button
|
|
801
|
-
class="calendar-new-row"
|
|
802
|
-
aria-label="+ New row"
|
|
803
|
-
?disabled=${this.logic.isInteracting}
|
|
804
|
-
@click=${() => this.logic.createRowOnDate(day.date)}
|
|
805
|
-
>
|
|
806
|
-
${PlusIcon()}<span>New row</span>
|
|
807
|
-
</button>`
|
|
808
|
-
: nothing}
|
|
809
|
-
</div>
|
|
810
|
-
`;
|
|
811
|
-
})}
|
|
812
|
-
<div class="calendar-segments">
|
|
813
|
-
${weekSegments
|
|
814
|
-
.filter(s => !this.logic.isEntryBeingMoved(s.entry.id))
|
|
815
|
-
.map(segment => this.renderEntry(segment.entry, `grid-column:${segment.startIndex + 1} / span ${segment.span};grid-row:${segment.slot + 1};`, segment))}
|
|
816
|
-
${this.renderSegmentPreview(preview)}
|
|
817
|
-
</div>
|
|
818
|
-
</div>
|
|
819
|
-
`;
|
|
820
|
-
})}
|
|
821
|
-
</div>
|
|
822
|
-
</div>
|
|
823
|
-
`;
|
|
824
|
-
}
|
|
825
|
-
render() {
|
|
826
|
-
const setup = this.logic.view.dateMapping$.value.status === 'setup';
|
|
827
|
-
return html `
|
|
828
|
-
${this.logic.headerWidget
|
|
829
|
-
? renderUniLit(this.logic.headerWidget, {
|
|
830
|
-
dataViewLogic: this.logic,
|
|
831
|
-
})
|
|
832
|
-
: nothing}
|
|
833
|
-
<div class=${setup ? 'calendar-setup-wrap' : ''}>
|
|
834
|
-
<div class="calendar-scroll" @wheel="${this.logic.onWheel}">
|
|
835
|
-
${this.renderCalendar(setup)}
|
|
836
|
-
</div>
|
|
837
|
-
${setup
|
|
838
|
-
? html `<div class="calendar-setup">
|
|
839
|
-
<button
|
|
840
|
-
@click=${(event) => this.logic.openSetupMenu(event.currentTarget)}
|
|
841
|
-
>
|
|
842
|
-
${TodayIcon()}<span>Select or create date property</span>
|
|
843
|
-
</button>
|
|
844
|
-
</div>`
|
|
845
|
-
: nothing}
|
|
846
|
-
</div>
|
|
847
|
-
`;
|
|
848
|
-
}
|
|
849
|
-
}
|