@dooc-dev/dooc 0.0.26 → 0.0.27
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/dist/edit.global.js +280 -260
- package/dist/engine/compiler/format-collections.js +1 -1
- package/dist/engine/core/html.js +2 -4
- package/dist/engine/core/icons.js +2 -2
- package/dist/frontend/document-application.js +160 -73
- package/dist/frontend/git-style.d.ts +1 -0
- package/dist/frontend/git-style.js +172 -0
- package/dist/frontend/language-picker.d.ts +5 -1
- package/dist/frontend/language-picker.js +19 -4
- package/dist/frontend/link-preview.d.ts +2 -0
- package/dist/frontend/link-preview.js +385 -0
- package/dist/frontend/locales/eng.json +137 -3
- package/dist/frontend/locales/jpn.json +139 -5
- package/dist/frontend/locales/zho.json +137 -3
- package/dist/frontend/resource-download.js +11 -6
- package/dist/frontend/scrollbars.d.ts +1 -0
- package/dist/frontend/scrollbars.js +9 -0
- package/dist/frontend/video-ui.js +9 -3
- package/dist/manifest.global.js +188 -186
- package/dist/mcp-relay.mjs +20 -1
- package/dist/plugins.global.js +31 -31
- package/dist/server/git-origin.js +1 -1
- package/dist/server/git.js +49 -26
- package/dist/server/operation-log.js +9 -1
- package/dist/server/serve.d.ts +1 -0
- package/dist/server/serve.js +18 -7
- package/dist/server/static-client.js +4 -14
- package/dist/server/workspace-server.js +2 -1
- package/dist/subformats.global.js +57 -57
- package/dist/ui.global.js +71 -69
- package/dist/workspace/git-review.d.ts +5 -0
- package/dist/workspace/git-review.js +56 -0
- package/dist/workspace/git-types.d.ts +29 -2
- package/dist/workspace/git-types.js +5 -1
- package/dist/workspace/github.d.ts +1 -1
- package/dist/workspace/github.js +73 -9
- package/dist/workspace/mcp-tools.js +20 -1
- package/dist/workspace-worker.global.js +332 -84
- package/package.json +1 -1
- package/dist/workspace-mcp-worker.global.js +0 -3263
- package/dist/workspace-reader-mcp-worker.global.js +0 -3263
- package/dist/workspace-reader-worker.global.js +0 -3263
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
export const GIT_CSS = `
|
|
2
|
+
body.edit:has(#preview-panes:not(.split) .preview-pane.active .git-page) #panel { display: none; }
|
|
3
|
+
.preview-pane.resources-pane:has(.git-page) { background: var(--c-bg0); }
|
|
4
|
+
.git-page { container: git-console / inline-size; width: 100%; min-width: 0; color: var(--c-fg); font: 14px/1.5 var(--font-sans); }
|
|
5
|
+
.git-page > #git-manager { max-width: 1100px; min-width: 0; margin: 0 auto; padding: 28px 0; }
|
|
6
|
+
.git-page [hidden] { display: none !important; }
|
|
7
|
+
.git-page details > summary { opacity: 1; }
|
|
8
|
+
.git-controls { min-width: 0; margin: 0; padding: 0; border: 0; }
|
|
9
|
+
.git-header, .git-identity, .git-toolbar, .git-branches, .git-section-head, .git-section-title, .git-actions, .git-checkbox { display: flex; align-items: center; gap: 8px; }
|
|
10
|
+
.git-header, .git-section-head { flex-wrap: wrap; justify-content: space-between; gap: 12px 18px; }
|
|
11
|
+
.git-header { justify-content: flex-start; }
|
|
12
|
+
.git-header .git-toolbar { margin-inline-start: auto; }
|
|
13
|
+
.git-page :is(h1,h2,h3,p,pre) { margin: 0; }
|
|
14
|
+
.git-page h1, .git-page h2, .git-page h3 { padding: 0; border: 0; color: var(--c-fg); font-family: var(--font-sans); }
|
|
15
|
+
.git-identity { min-width: 0; gap: 10px; }
|
|
16
|
+
.git-header h1 { margin: 0; overflow-wrap: anywhere; font-size: 24px; line-height: 1.2; font-weight: 650; letter-spacing: -.025em; }
|
|
17
|
+
.git-page h2 { font-size: 16px; font-weight: 600; line-height: 1.4; }
|
|
18
|
+
.git-icon { display: inline-flex; flex: none; align-items: center; justify-content: center; }
|
|
19
|
+
.git-identity > .git-icon { width: 34px; height: 34px; border-radius: 7px; background: var(--c-bg1); color: var(--c-fg-muted); }
|
|
20
|
+
.git-identity > .git-icon svg { width: 22px; height: 22px; }
|
|
21
|
+
.git-toolbar, .git-actions { flex-wrap: wrap; gap: 6px; }
|
|
22
|
+
.git-page .git-button, .git-new-branch > summary { display: inline-flex; box-sizing: border-box; align-items: center; justify-content: center; gap: 5px;
|
|
23
|
+
min-height: 32px; padding: 4px 10px; border: 1px solid var(--c-line); border-radius: 5px; color: var(--c-fg); background: var(--c-bg0); font: 500 12px/1.4 var(--font-sans); cursor: pointer; }
|
|
24
|
+
.git-page .git-button:not(:disabled):hover, .git-new-branch > summary:hover { background: var(--c-raised); }
|
|
25
|
+
.git-page .git-button:disabled { color: var(--c-fg-muted); background: var(--c-bg1); opacity: .65; cursor: default; }
|
|
26
|
+
.git-page :is(button,summary,a,input,textarea,select,pre):focus-visible { outline: 2px solid var(--c-accent); outline-offset: 2px; }
|
|
27
|
+
.git-page :is(input:not([type=checkbox]),textarea,select) { box-sizing: border-box; min-width: 0; max-width: 100%; margin: 0; border: 1px solid var(--c-line);
|
|
28
|
+
border-radius: 5px; padding: 6px 9px; background: var(--c-bg0); color: var(--c-fg); font: 13px/1.5 var(--font-sans); }
|
|
29
|
+
.git-page :is(input,textarea)::placeholder { color: var(--c-fg-faint); opacity: 1; }
|
|
30
|
+
.git-page select option { background: var(--c-bg0); color: var(--c-fg); }
|
|
31
|
+
.git-branches { flex-wrap: wrap; gap: 6px 12px; min-width: 0; }
|
|
32
|
+
.git-branch-select { display: inline-flex; align-items: center; gap: 3px; min-width: 0; max-width: 100%; color: var(--c-fg-muted); }
|
|
33
|
+
.git-branch-select select { width: auto; max-width: min(48ch,100% - 22px); border-color: transparent; padding: 4px 2px; color: var(--c-fg); font: 13px var(--doc-mono); text-overflow: ellipsis; }
|
|
34
|
+
.git-revision { border-inline-start: 1px solid var(--c-line); padding-inline-start: 12px; color: var(--c-fg-muted); font: 12px var(--doc-mono); }
|
|
35
|
+
.git-new-branch { min-width: 0; max-width: 100%; }
|
|
36
|
+
.git-new-branch > summary { border-color: transparent; background: none; color: var(--c-fg-muted); list-style: none; }
|
|
37
|
+
.git-new-branch > summary::before { content: "+"; font: 16px var(--doc-mono); }
|
|
38
|
+
.git-new-branch[open] { flex-basis: 100%; }
|
|
39
|
+
.git-new-branch[open] > summary::before { content: "−"; }
|
|
40
|
+
.git-new-branch > summary::-webkit-details-marker { display: none; }
|
|
41
|
+
.git-new-branch form { margin: 6px 0 4px; }
|
|
42
|
+
.git-tabs { display: flex; flex-wrap: wrap; gap: 18px; margin: 19px 0 22px; border-bottom: 1px solid var(--c-line); }
|
|
43
|
+
.git-tabs a { display: inline-flex; align-items: center; gap: 7px; min-height: 36px; padding-inline: 2px; border-bottom: 2px solid transparent; color: var(--c-fg-muted); text-decoration: none; font-size: 13px; }
|
|
44
|
+
.git-tabs a:hover { color: var(--c-fg); }
|
|
45
|
+
.git-tabs a[aria-current] { border-color: var(--c-accent); color: var(--c-fg); font-weight: 600; }
|
|
46
|
+
.git-pr-filters { align-self: center; justify-content: flex-end; max-width: 100%; margin: 0 0 4px auto; }
|
|
47
|
+
.git-pr-filters .git-button { min-width: 0; max-width: 100%; overflow-wrap: anywhere; }
|
|
48
|
+
.git-page .git-commit-jump { display: none; }
|
|
49
|
+
.git-count { display: inline-block; min-width: 1.6em; padding: 1px 5px; border-radius: 4px; background: var(--c-raised); color: var(--c-fg-muted); font: 500 11px/1.5 var(--font-sans); font-variant-numeric: tabular-nums; text-align: center; }
|
|
50
|
+
.git-workspace { display: grid; align-items: start; grid-template-columns: minmax(0,1fr) minmax(240px,30%); gap: 32px; }
|
|
51
|
+
.git-content, .git-side, .git-files, .git-group { min-width: 0; }
|
|
52
|
+
.git-side { display: grid; align-content: start; gap: 20px; }
|
|
53
|
+
.git-section-head { margin-bottom: 14px; }
|
|
54
|
+
.git-search { display: flex; align-items: center; align-self: center; gap: 6px; min-width: 0; width: min(190px,100%); margin: 0 0 4px auto; box-sizing: border-box; padding-inline: 8px; border: 1px solid var(--c-line); border-radius: 5px; color: var(--c-fg-muted); }
|
|
55
|
+
.git-search input[type=search] { width: 100%; min-height: 30px; padding: 4px 0; border: 0; background: transparent; }
|
|
56
|
+
.git-search:focus-within { outline: 2px solid var(--c-accent); outline-offset: 1px; }
|
|
57
|
+
.git-search input:focus-visible { outline: none; }
|
|
58
|
+
.git-groups { display: grid; gap: 16px; }
|
|
59
|
+
.git-group { border: 1px solid var(--c-line); border-radius: 6px; }
|
|
60
|
+
.git-page .git-group-title { display: flex; align-items: center; gap: 8px; min-height: 36px; padding-inline: 12px; border-radius: 5px 5px 0 0; background: var(--c-bg1); font: 600 13px var(--font-sans); }
|
|
61
|
+
.git-file { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 0 8px; border-top: 1px solid var(--c-line-soft); }
|
|
62
|
+
.git-file:has(.git-file-open[aria-expanded=true]) { background: var(--c-bg1); }
|
|
63
|
+
.git-file-open { display: grid; grid-template-columns: 6px minmax(0,1fr) auto; align-items: center; gap: 10px; min-width: 0; min-height: 40px; padding: 6px 0 6px 12px;
|
|
64
|
+
border: 0; border-radius: 3px; background: none; color: var(--c-fg); text-align: start; cursor: pointer; }
|
|
65
|
+
.git-file-open:hover .git-filename { text-decoration: underline; text-underline-offset: 3px; }
|
|
66
|
+
.git-file-open::before, .git-pr-open::before, .git-review-file > summary::before { content: ""; width: 5px; height: 5px; border-right: 1.5px solid var(--c-fg-muted); border-bottom: 1.5px solid var(--c-fg-muted); transform: rotate(-45deg); }
|
|
67
|
+
.git-file-open[aria-expanded=true]::before, .git-pr-open[aria-expanded=true]::before, .git-review-file[open] > summary::before { transform: rotate(45deg); }
|
|
68
|
+
.git-file-path { display: flex; flex-wrap: wrap; align-items: baseline; gap: 1px 9px; min-width: 0; overflow-wrap: anywhere; }
|
|
69
|
+
.git-filename { font: 500 13px/1.4 var(--doc-mono); }
|
|
70
|
+
.git-directory, .git-upstream { color: var(--c-fg-muted); font: 12px/1.4 var(--doc-mono); }
|
|
71
|
+
.git-file-status { color: var(--c-fg-muted); font: 500 12px/1.4 var(--font-sans); }
|
|
72
|
+
.git-file-status:is([data-status=A],[data-status="?"]) { color: var(--c-ok); }
|
|
73
|
+
.git-file-status:is([data-status=M],[data-status=T]) { color: var(--c-warn); }
|
|
74
|
+
.git-file-status:is([data-status=D],[data-status=U]) { color: var(--c-danger); }
|
|
75
|
+
.git-file > .git-button { margin-inline-end: 8px; border-color: transparent; background: transparent; }
|
|
76
|
+
.git-file > .git-button:has(> .git-icon:only-child) { min-width: 32px; padding-inline: 0; }
|
|
77
|
+
.git-file > .git-button svg { width: 15px; height: 15px; }
|
|
78
|
+
.git-patch { grid-column: 1/-1; min-width: 0; padding: 0 8px 8px; }
|
|
79
|
+
.git-page .git-diff { max-height: 320px; overflow: auto; padding: 8px 0; border: 1px solid var(--c-line); border-radius: 4px; background: var(--c-bg0); color: var(--c-fg); font: 12px/1.6 var(--doc-mono); white-space: pre; tab-size: 4; }
|
|
80
|
+
.git-line { display: block; width: max-content; min-width: 100%; box-sizing: border-box; padding: 0 8px; }
|
|
81
|
+
.git-line.meta { color: var(--c-fg-muted); }
|
|
82
|
+
.git-line.hunk { background: color-mix(in srgb,var(--c-info) 10%,var(--c-bg0)); color: var(--c-info); }
|
|
83
|
+
.git-line.add { background: color-mix(in srgb,var(--c-ok) 13%,var(--c-bg0)); }
|
|
84
|
+
.git-line.del { background: color-mix(in srgb,var(--c-danger) 12%,var(--c-bg0)); }
|
|
85
|
+
.git-more { margin: 8px 12px; }
|
|
86
|
+
.git-page .git-clean { padding: 24px 16px; border-block: 1px solid var(--c-line); color: var(--c-ok); font-weight: 550; }
|
|
87
|
+
.git-page .git-hint, .git-page .git-tracking { margin: 0; color: var(--c-fg-muted); font: 12px/1.5 var(--font-sans); overflow-wrap: anywhere; }
|
|
88
|
+
.git-form { display: grid; gap: 10px; }
|
|
89
|
+
.git-commit { gap: 7px; }
|
|
90
|
+
.git-commit-actions { align-items: flex-start; gap: 4px; }
|
|
91
|
+
.git-commit-options > summary { display: grid; place-items: center; width: 32px; min-height: 36px; box-sizing: border-box; list-style: none; border: 1px solid var(--c-line); border-radius: 5px; color: var(--c-fg-muted); cursor: pointer; }
|
|
92
|
+
.git-commit-options > summary::-webkit-details-marker { display: none; }
|
|
93
|
+
.git-commit-options > summary::after { content: ""; width: 6px; height: 6px; border: solid currentColor; border-width: 0 1.5px 1.5px 0; transform: rotate(45deg); }
|
|
94
|
+
.git-commit-options[open] > summary::after { transform: rotate(225deg); }
|
|
95
|
+
.git-commit-options > button { margin-top: 4px; }
|
|
96
|
+
.git-section-title > .git-icon { color: var(--c-fg-muted); }
|
|
97
|
+
.git-provider { color: var(--c-fg-muted); font-size: 12px; font-weight: 400; overflow-wrap: anywhere; }
|
|
98
|
+
.git-staged-total { margin: 9px 0 0 auto; color: var(--c-fg-muted); font: 500 12px var(--font-sans); font-variant-numeric: tabular-nums; }
|
|
99
|
+
.git-field { display: grid; gap: 5px; min-width: 0; color: var(--c-fg-muted); font: 500 12px/1.5 var(--font-sans); }
|
|
100
|
+
.git-field textarea { width: 100%; resize: vertical; }
|
|
101
|
+
.git-commit textarea { width: 100%; min-height: 60px; resize: vertical; }
|
|
102
|
+
.git-page .git-primary { min-height: 36px; }
|
|
103
|
+
.git-page .git-primary:not(:disabled) { color: var(--doc-accent-fg); border-color: transparent; background: color-mix(in srgb,var(--c-accent) 85%,black); }
|
|
104
|
+
.git-page .git-primary:not(:disabled):hover { background: color-mix(in srgb,var(--c-accent) 75%,black); }
|
|
105
|
+
.git-page .git-primary:disabled { background: var(--c-raised); opacity: 1; }
|
|
106
|
+
.git-sync, .git-stash { display: grid; justify-items: start; gap: 8px; padding: 0 1px; }
|
|
107
|
+
.git-stash .git-button { border-color: transparent; color: var(--c-fg-muted); }
|
|
108
|
+
.git-page .git-upstream { display: block; max-width: 100%; padding: 0; background: none; overflow-wrap: anywhere; }
|
|
109
|
+
.git-prs { display: grid; gap: 0; }
|
|
110
|
+
.git-prs > .git-button { justify-self: start; margin-top: 8px; }
|
|
111
|
+
.git-pr-create { margin-bottom: 18px; padding: 14px; border: 1px solid var(--c-line); border-radius: 6px; background: var(--c-bg1); }
|
|
112
|
+
.git-pr-create h3 { font-size: 15px; }
|
|
113
|
+
.git-pr-row { display: grid; grid-template: "title link" auto "meta meta" auto "body body" auto / minmax(0,1fr) auto; align-items: start; column-gap: 16px; min-width: 0; border-top: 1px solid var(--c-line); }
|
|
114
|
+
.git-pr-open { grid-area: title; display: grid; grid-template-columns: 6px auto minmax(0,1fr) auto; align-items: baseline; gap: 2px 8px; min-width: 0; padding: 10px 2px 2px; border: 0; color: inherit; background: none; font: inherit; text-align: start; cursor: pointer; }
|
|
115
|
+
.git-pr-open::before { align-self: start; margin-top: 7px; }
|
|
116
|
+
.git-pr-open:hover .git-pr-title { text-decoration: underline; text-underline-offset: 3px; }
|
|
117
|
+
.git-pr-number, .git-pr-route { font: 12px/1.5 var(--doc-mono); color: var(--c-fg-muted); overflow-wrap: anywhere; }
|
|
118
|
+
.git-pr-title { min-width: 0; font-weight: 600; overflow-wrap: anywhere; }
|
|
119
|
+
.git-pr-state { font-size: 12px; color: var(--c-fg-muted); }
|
|
120
|
+
.git-pr-state[data-state=open] { color: var(--c-ok); }
|
|
121
|
+
.git-pr-state[data-state=merged] { color: var(--c-info); }
|
|
122
|
+
.git-pr-meta { grid-area: meta; display: flex; align-items: baseline; flex-wrap: wrap; gap: 3px 14px; min-width: 0; padding: 2px 0 10px 16px; }
|
|
123
|
+
.git-pr-head { min-width: 0; color: var(--c-fg-muted); font: 12px/1.5 var(--doc-mono); }
|
|
124
|
+
.git-pr-head > summary { cursor: pointer; }
|
|
125
|
+
.git-pr-head .git-full-sha { display: block; margin: 4px 0; color: var(--c-fg); overflow-wrap: anywhere; user-select: all; }
|
|
126
|
+
.git-pr-checks { font-size: 12px; color: var(--c-fg-muted); overflow-wrap: anywhere; }
|
|
127
|
+
.git-pr-body { grid-area: body; display: grid; grid-template-columns: minmax(0,1fr); gap: 12px; padding: 2px 0 14px; }
|
|
128
|
+
.git-description { max-height: 18em; overflow: auto; white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
129
|
+
.git-pr-body summary { min-height: 30px; color: var(--c-fg); font-size: 13px; font-weight: 500; cursor: pointer; }
|
|
130
|
+
.git-pr-files, .git-pr-review, .git-pr-edit { min-width: 0; padding-block: 4px; border-top: 1px solid var(--c-line-soft); }
|
|
131
|
+
.git-review-files { min-width: 0; }
|
|
132
|
+
.git-review-file > summary { display: flex; align-items: center; gap: 8px; padding: 5px 8px; background: var(--c-bg1); }
|
|
133
|
+
.git-review-file > summary::before { flex: none; }
|
|
134
|
+
.git-review-file .git-filename { flex: 1; overflow-wrap: anywhere; }
|
|
135
|
+
.git-added { color: color-mix(in srgb,var(--c-ok) 85%,var(--c-fg)); }
|
|
136
|
+
.git-deleted { color: color-mix(in srgb,var(--c-danger) 85%,var(--c-fg)); }
|
|
137
|
+
.git-merge { border-top: 1px solid var(--c-line-soft); padding-top: 10px; }
|
|
138
|
+
.git-review-link { grid-area: link; display: inline-flex; align-items: center; justify-self: start; padding: 10px 0 2px; color: var(--c-info); font-size: 13px; text-underline-offset: 3px; overflow-wrap: anywhere; }
|
|
139
|
+
.git-prs .git-checkbox { color: var(--c-fg-muted); font-size: 13px; }
|
|
140
|
+
.git-feedback { position: sticky; top: 4px; z-index: 2; display: flex; align-items: center; gap: 8px; margin-bottom: 12px; padding: 8px 10px; border: 1px solid var(--c-line); border-radius: 5px; background: var(--c-bg1); }
|
|
141
|
+
.git-notice, .git-error { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 13px; }
|
|
142
|
+
.git-feedback[data-kind=error], .git-error { color: var(--c-danger); }
|
|
143
|
+
.git-feedback[data-kind=success] { color: var(--c-ok); }
|
|
144
|
+
@container git-console (max-width: 680px) {
|
|
145
|
+
.git-page > #git-manager { padding-block: 16px; }
|
|
146
|
+
.git-workspace { grid-template-columns: minmax(0,1fr); gap: 18px; }
|
|
147
|
+
.git-tabs { margin-block: 13px 16px; }
|
|
148
|
+
.git-page .git-commit-jump { display: inline-flex; margin-inline-start: auto; align-self: center; border-color: transparent; }
|
|
149
|
+
.git-side { gap: 16px; }
|
|
150
|
+
}
|
|
151
|
+
@container git-console (max-width: 430px) {
|
|
152
|
+
.git-header h1 { font-size: 20px; }
|
|
153
|
+
.git-identity > .git-icon { width: 26px; height: 26px; }
|
|
154
|
+
.git-section-head { gap: 8px; }
|
|
155
|
+
.git-tabs { gap: 4px 14px; }
|
|
156
|
+
.git-pr-filters select { field-sizing: content; }
|
|
157
|
+
.git-search { order: 1; flex-basis: 100%; margin: 2px 0 8px; }
|
|
158
|
+
.git-file-open { gap: 7px; padding-inline-start: 8px; }
|
|
159
|
+
.git-file > .git-button { margin-inline-end: 4px; padding-inline: 6px; }
|
|
160
|
+
.git-pr-row { grid-template: "title" auto "meta" auto "link" auto "body" auto / minmax(0,1fr); }
|
|
161
|
+
.git-pr-meta { padding-bottom: 2px; }
|
|
162
|
+
.git-review-link { margin-inline-start: 16px; padding-block: 3px 8px; }
|
|
163
|
+
}
|
|
164
|
+
@media (max-width: 820px) {
|
|
165
|
+
body.edit:has(#preview-panes:not(.split) .preview-pane.active .git-page) { grid-template-rows: minmax(0,1fr) 0; }
|
|
166
|
+
}
|
|
167
|
+
@media (pointer: coarse) {
|
|
168
|
+
.git-page :is(.git-button, .git-file-open, .git-pr-open, .git-review-link, summary, select, .git-tabs a) { min-height: 44px; }
|
|
169
|
+
.git-page :is(input:not([type=checkbox]),textarea,select) { font-size: 16px; }
|
|
170
|
+
.git-page .git-file > .git-button, .git-commit-options > summary { min-width: 44px; }
|
|
171
|
+
}
|
|
172
|
+
`;
|
|
@@ -1,2 +1,6 @@
|
|
|
1
1
|
/** Keep the native select as the value and change-event source. */
|
|
2
|
-
export declare const mountSelectPickers: (t: (key: string) => string, selects?: Iterable<HTMLSelectElement
|
|
2
|
+
export declare const mountSelectPickers: (t: (key: string) => string, selects?: Iterable<HTMLSelectElement>, settings?: {
|
|
3
|
+
minWidth?: number;
|
|
4
|
+
renderOption?: (item: HTMLButtonElement, option: HTMLOptionElement) => void;
|
|
5
|
+
onAction?: () => void;
|
|
6
|
+
}) => (() => void);
|
|
@@ -15,7 +15,7 @@ const fitWorkspaceLabel = (input, label) => {
|
|
|
15
15
|
}
|
|
16
16
|
};
|
|
17
17
|
/** Keep the native select as the value and change-event source. */
|
|
18
|
-
export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-lang, #ui-language")) => {
|
|
18
|
+
export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-lang, #ui-language"), settings = {}) => {
|
|
19
19
|
const disposers = [];
|
|
20
20
|
for (const select of selects) {
|
|
21
21
|
const translations = select.id === "fm-lang";
|
|
@@ -48,6 +48,8 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
48
48
|
list.setAttribute("role", "listbox");
|
|
49
49
|
if (translations) {
|
|
50
50
|
list.setAttribute("aria-multiselectable", "true");
|
|
51
|
+
}
|
|
52
|
+
if (translations || settings.onAction) {
|
|
51
53
|
input.setAttribute("aria-keyshortcuts", "Control+Enter");
|
|
52
54
|
}
|
|
53
55
|
input.setAttribute("aria-controls", list.id);
|
|
@@ -70,14 +72,14 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
70
72
|
const selectedText = () => (versions ? select.selectedOptions[0]?.value : select.selectedOptions[0]?.text) ?? "";
|
|
71
73
|
const position = () => {
|
|
72
74
|
const rect = input.getBoundingClientRect();
|
|
73
|
-
const width = workspace || versions
|
|
74
|
-
? Math.min(Math.max(rect.width, workspace ? 280 : 180), innerWidth - 16)
|
|
75
|
+
const width = workspace || versions || settings.minWidth
|
|
76
|
+
? Math.min(Math.max(rect.width, settings.minWidth ?? (workspace ? 280 : 180)), innerWidth - 16)
|
|
75
77
|
: rect.width;
|
|
76
78
|
const below = innerHeight - rect.bottom;
|
|
77
79
|
const above = below < 240 && rect.top > below;
|
|
78
80
|
Object.assign(popup.style, {
|
|
79
81
|
width: `${width}px`,
|
|
80
|
-
left: `${workspace || versions ? Math.max(8, Math.min(workspace ? rect.left + (rect.width - width) / 2 : rect.left, innerWidth - width - 8)) : rect.left}px`,
|
|
82
|
+
left: `${workspace || versions || settings.minWidth ? Math.max(8, Math.min(workspace ? rect.left + (rect.width - width) / 2 : rect.left, innerWidth - width - 8)) : rect.left}px`,
|
|
81
83
|
maxHeight: `${Math.max(80, Math.min(360, (above ? rect.top : below) - 12))}px`,
|
|
82
84
|
top: above ? "auto" : `${rect.bottom + 4}px`,
|
|
83
85
|
bottom: above ? `${innerHeight - rect.top + 4}px` : "auto",
|
|
@@ -161,6 +163,7 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
161
163
|
item.prepend(marker);
|
|
162
164
|
item.setAttribute("aria-current", String(option.selected));
|
|
163
165
|
}
|
|
166
|
+
settings.renderOption?.(item, option);
|
|
164
167
|
if (option.selected)
|
|
165
168
|
selected = count;
|
|
166
169
|
if (option.value === highlighted)
|
|
@@ -200,6 +203,8 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
200
203
|
input.setAttribute("aria-label", select.getAttribute("aria-label") ?? t("Language"));
|
|
201
204
|
if (translations)
|
|
202
205
|
input.setAttribute("aria-description", t("Enter to edit; Ctrl+Enter to add or remove translation"));
|
|
206
|
+
if (settings.onAction)
|
|
207
|
+
input.setAttribute("aria-description", t("Enter to select; Ctrl+Enter to configure"));
|
|
203
208
|
if (!isOpen() || !query) {
|
|
204
209
|
if (workspace)
|
|
205
210
|
fitWorkspaceLabel(input, selectedText());
|
|
@@ -245,6 +250,12 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
245
250
|
return;
|
|
246
251
|
select.dispatchEvent(new CustomEvent("docs:toggle-language", { detail: item.dataset.value }));
|
|
247
252
|
};
|
|
253
|
+
const act = (item) => {
|
|
254
|
+
if (!item || select.disabled)
|
|
255
|
+
return;
|
|
256
|
+
choose(item);
|
|
257
|
+
settings.onAction?.();
|
|
258
|
+
};
|
|
248
259
|
const open = () => {
|
|
249
260
|
if (isOpen() || select.disabled)
|
|
250
261
|
return;
|
|
@@ -293,6 +304,8 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
293
304
|
const item = list.querySelector('[data-active="true"]');
|
|
294
305
|
if (translations && event.ctrlKey)
|
|
295
306
|
toggle(item);
|
|
307
|
+
else if (settings.onAction && event.ctrlKey)
|
|
308
|
+
act(item);
|
|
296
309
|
else
|
|
297
310
|
choose(item);
|
|
298
311
|
}
|
|
@@ -314,6 +327,8 @@ export const mountSelectPickers = (t, selects = document.querySelectorAll("#fm-l
|
|
|
314
327
|
const item = target.closest("button");
|
|
315
328
|
if (translations && target.closest(".language-toggle"))
|
|
316
329
|
toggle(item);
|
|
330
|
+
else if (settings.onAction && target.closest("[data-picker-action]"))
|
|
331
|
+
act(item);
|
|
317
332
|
else
|
|
318
333
|
choose(item);
|
|
319
334
|
});
|
|
@@ -0,0 +1,385 @@
|
|
|
1
|
+
import { SCROLLBAR_CSS } from "./scrollbars.js";
|
|
2
|
+
/** Self-contained so workspace readers and standalone documents share previews. */
|
|
3
|
+
export function mountLinkPreviews(request = fetch, network = true, scrollbars = SCROLLBAR_CSS) {
|
|
4
|
+
const t = (key) => window.__docsTranslate?.(key) ??
|
|
5
|
+
key;
|
|
6
|
+
let active;
|
|
7
|
+
let popup;
|
|
8
|
+
let controller;
|
|
9
|
+
let timer;
|
|
10
|
+
let closeTimer;
|
|
11
|
+
let title = null;
|
|
12
|
+
let description = null;
|
|
13
|
+
let press;
|
|
14
|
+
let hoverPoint;
|
|
15
|
+
let suppressClick = false;
|
|
16
|
+
let restoringFocus = false;
|
|
17
|
+
document.body.dataset.linkPreviews = "";
|
|
18
|
+
const close = () => {
|
|
19
|
+
clearTimeout(timer);
|
|
20
|
+
clearTimeout(closeTimer);
|
|
21
|
+
controller?.abort();
|
|
22
|
+
const origin = active;
|
|
23
|
+
const host = popup;
|
|
24
|
+
const modal = host instanceof HTMLDialogElement;
|
|
25
|
+
if (active && title !== null)
|
|
26
|
+
active.setAttribute("title", title);
|
|
27
|
+
if (active && popup) {
|
|
28
|
+
if (description === null)
|
|
29
|
+
active.removeAttribute("aria-describedby");
|
|
30
|
+
else
|
|
31
|
+
active.setAttribute("aria-describedby", description);
|
|
32
|
+
}
|
|
33
|
+
active?.removeAttribute("data-link-preview-press");
|
|
34
|
+
active = popup = undefined;
|
|
35
|
+
press = hoverPoint = undefined;
|
|
36
|
+
title = null;
|
|
37
|
+
restoringFocus = true;
|
|
38
|
+
if (modal)
|
|
39
|
+
host.close();
|
|
40
|
+
host?.remove();
|
|
41
|
+
if (modal && origin?.isConnected)
|
|
42
|
+
origin.focus({ preventScroll: true });
|
|
43
|
+
restoringFocus = false;
|
|
44
|
+
};
|
|
45
|
+
const position = () => {
|
|
46
|
+
if (!active || !popup || popup instanceof HTMLDialogElement)
|
|
47
|
+
return;
|
|
48
|
+
const rect = active.getBoundingClientRect();
|
|
49
|
+
const below = innerHeight - rect.bottom;
|
|
50
|
+
popup.style.left = `${Math.max(12, Math.min(rect.left, innerWidth - popup.offsetWidth - 12))}px`;
|
|
51
|
+
popup.style.top = `${Math.max(12, Math.min(innerHeight - popup.offsetHeight - 12, below >= popup.offsetHeight + 12 ? rect.bottom + 8 : rect.top - popup.offsetHeight - 8))}px`;
|
|
52
|
+
};
|
|
53
|
+
const show = async (target, overlay = false) => {
|
|
54
|
+
if (active !== target ||
|
|
55
|
+
!target.isConnected ||
|
|
56
|
+
window.getSelection()?.isCollapsed === false)
|
|
57
|
+
return;
|
|
58
|
+
const control = new AbortController();
|
|
59
|
+
controller = control;
|
|
60
|
+
const signal = control.signal;
|
|
61
|
+
const templates = [
|
|
62
|
+
...document.querySelectorAll("template[data-route]"),
|
|
63
|
+
];
|
|
64
|
+
const file = target.dataset.resourceSource ??
|
|
65
|
+
target.closest("[data-record-file]")?.dataset.recordFile;
|
|
66
|
+
const href = target.dataset.jumpUrl ??
|
|
67
|
+
target.getAttribute("href") ??
|
|
68
|
+
(file ? `${templates.length ? "#" : ""}/_files/file/${encodeURIComponent(file)}` : "");
|
|
69
|
+
if (!href)
|
|
70
|
+
return;
|
|
71
|
+
let url;
|
|
72
|
+
try {
|
|
73
|
+
url = new URL(href, location.href);
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (!["http:", "https:", "file:"].includes(url.protocol) || url.username || url.password)
|
|
79
|
+
return;
|
|
80
|
+
const host = document.createElement(overlay ? "dialog" : "div");
|
|
81
|
+
popup = host;
|
|
82
|
+
host.className = "link-preview";
|
|
83
|
+
host.id = "dooc-link-preview";
|
|
84
|
+
description = target.getAttribute("aria-describedby");
|
|
85
|
+
if (!overlay) {
|
|
86
|
+
host.popover = "manual";
|
|
87
|
+
host.setAttribute("role", "tooltip");
|
|
88
|
+
target.setAttribute("aria-describedby", [description, host.id].filter(Boolean).join(" "));
|
|
89
|
+
}
|
|
90
|
+
const heading = document.createElement("strong");
|
|
91
|
+
heading.id = `${host.id}-title`;
|
|
92
|
+
heading.textContent =
|
|
93
|
+
target.getAttribute("aria-label") ||
|
|
94
|
+
title ||
|
|
95
|
+
target.firstChild?.textContent?.trim() ||
|
|
96
|
+
file ||
|
|
97
|
+
url.hostname;
|
|
98
|
+
const source = document.createElement("div");
|
|
99
|
+
source.className = "link-preview-source";
|
|
100
|
+
source.textContent = file || href;
|
|
101
|
+
const status = document.createElement("p");
|
|
102
|
+
status.textContent = t("Loading…");
|
|
103
|
+
status.setAttribute("role", "status");
|
|
104
|
+
host.append(heading, source, status);
|
|
105
|
+
if (host instanceof HTMLDialogElement) {
|
|
106
|
+
host.setAttribute("aria-labelledby", heading.id);
|
|
107
|
+
const actions = document.createElement("div");
|
|
108
|
+
actions.className = "link-preview-actions";
|
|
109
|
+
const dismiss = document.createElement("button");
|
|
110
|
+
dismiss.type = "button";
|
|
111
|
+
dismiss.textContent = t("Close");
|
|
112
|
+
dismiss.autofocus = true;
|
|
113
|
+
dismiss.addEventListener("click", close);
|
|
114
|
+
const open = document.createElement("button");
|
|
115
|
+
open.type = "button";
|
|
116
|
+
open.textContent = t("Open link");
|
|
117
|
+
open.addEventListener("click", () => {
|
|
118
|
+
close();
|
|
119
|
+
target.click();
|
|
120
|
+
});
|
|
121
|
+
actions.append(dismiss, open);
|
|
122
|
+
host.append(actions);
|
|
123
|
+
host.addEventListener("cancel", (event) => {
|
|
124
|
+
event.preventDefault();
|
|
125
|
+
close();
|
|
126
|
+
});
|
|
127
|
+
host.addEventListener("click", (event) => {
|
|
128
|
+
const rect = host.getBoundingClientRect();
|
|
129
|
+
if (event.target === host &&
|
|
130
|
+
(event.clientX < rect.left ||
|
|
131
|
+
event.clientX > rect.right ||
|
|
132
|
+
event.clientY < rect.top ||
|
|
133
|
+
event.clientY > rect.bottom))
|
|
134
|
+
close();
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
(target.closest("[data-theme], main") ?? document.body).append(host);
|
|
138
|
+
if (host instanceof HTMLDialogElement) {
|
|
139
|
+
suppressClick = true;
|
|
140
|
+
host.showModal();
|
|
141
|
+
}
|
|
142
|
+
else
|
|
143
|
+
host.showPopover();
|
|
144
|
+
position();
|
|
145
|
+
const frame = document.createElement("iframe");
|
|
146
|
+
frame.title = heading.textContent || t("Preview");
|
|
147
|
+
frame.sandbox.value = "";
|
|
148
|
+
frame.referrerPolicy = "no-referrer";
|
|
149
|
+
// Keep keyboard focus on the dialog controls instead of entering a sandboxed frame.
|
|
150
|
+
frame.tabIndex = -1;
|
|
151
|
+
const present = (html) => {
|
|
152
|
+
if (signal.aborted || popup !== host)
|
|
153
|
+
return;
|
|
154
|
+
const theme = getComputedStyle(target);
|
|
155
|
+
const palette = [
|
|
156
|
+
"--doc-fg",
|
|
157
|
+
"--doc-fg-2",
|
|
158
|
+
"--doc-bg",
|
|
159
|
+
"--doc-border",
|
|
160
|
+
"--doc-accent",
|
|
161
|
+
"--doc-accent-2",
|
|
162
|
+
"--font-sans",
|
|
163
|
+
"--doc-mono",
|
|
164
|
+
]
|
|
165
|
+
.map((name) => `${name}:${theme.getPropertyValue(name)};`)
|
|
166
|
+
.join("");
|
|
167
|
+
frame.srcdoc = `<!doctype html><meta charset="utf-8"><style>:root{${palette}color-scheme:${theme.colorScheme}}*{box-sizing:border-box}${scrollbars}html{overscroll-behavior:contain}body{margin:0;padding:12px;font:${overlay ? "15px" : "13px"}/1.6 var(--font-sans,system-ui);color:var(--doc-fg,CanvasText);background:var(--doc-bg,Canvas);overflow-wrap:anywhere}::selection{background:color-mix(in srgb,var(--doc-accent) 24%,transparent)}a{color:var(--doc-accent-2);text-underline-offset:2px}img,video,object,iframe{display:block;max-width:100%;max-height:240px;object-fit:contain}iframe{width:100%!important;border:0}pre{white-space:pre-wrap;font:12px/1.5 var(--doc-mono,monospace)}h1,h2,h3{margin:0 0 8px;font-size:16px}figure{margin:0}button,a[download],[data-resource-download],.pbtn,.doc-title,.resource-download-tools,.page-actions,.pane-actions,.subformat-card-tools,.codeblk-head,.res-crumbs{display:none}table{border-collapse:collapse}td,th{padding:4px 8px;overflow-wrap:break-word;border-bottom:1px solid var(--doc-border)}</style>${html}`;
|
|
168
|
+
status.replaceWith(frame);
|
|
169
|
+
position();
|
|
170
|
+
};
|
|
171
|
+
const nearby = target.querySelector(".figpop, .dictpop") ??
|
|
172
|
+
(target.matches(".subformat-card-open")
|
|
173
|
+
? target.closest(".subformat-card")?.querySelector(".format-preview")
|
|
174
|
+
: null);
|
|
175
|
+
if (nearby) {
|
|
176
|
+
present(nearby.innerHTML);
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
const internal = url.origin === location.origin &&
|
|
180
|
+
(url.protocol !== "file:" || url.pathname === location.pathname);
|
|
181
|
+
try {
|
|
182
|
+
if (internal) {
|
|
183
|
+
const routeHash = href.startsWith("#/");
|
|
184
|
+
const route = routeHash ? new URL(href.slice(1), url) : url;
|
|
185
|
+
const base = window.__doocClientBase?.replace(/\/$/, "") ?? "";
|
|
186
|
+
const path = !routeHash && base && route.pathname.startsWith(`${base}/`)
|
|
187
|
+
? route.pathname.slice(base.length)
|
|
188
|
+
: route.pathname;
|
|
189
|
+
const template = templates.find((item) => item.dataset.route === path.replace(/^\/+|\/$/g, "").split("?")[0]);
|
|
190
|
+
if (template && !template.dataset.src) {
|
|
191
|
+
present(template.innerHTML);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
if (href.startsWith("#") && !routeHash) {
|
|
195
|
+
const anchor = document.getElementById(decodeURIComponent(href.slice(1)));
|
|
196
|
+
if (anchor) {
|
|
197
|
+
present((anchor.closest("section") ?? anchor).outerHTML);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (!network && !template?.dataset.src)
|
|
202
|
+
throw new Error("Offline preview unavailable");
|
|
203
|
+
const workspace = target.closest("[data-workspace]")?.dataset.workspace;
|
|
204
|
+
const query = new URLSearchParams(route.search);
|
|
205
|
+
query.set("route", path);
|
|
206
|
+
const endpoint = template?.dataset.src ??
|
|
207
|
+
(document.body.classList.contains("edit")
|
|
208
|
+
? `/api/page?${query}`
|
|
209
|
+
: `${path}${route.search}`);
|
|
210
|
+
const response = await request(endpoint, { signal }, workspace);
|
|
211
|
+
if (!response.ok)
|
|
212
|
+
throw new Error(`Preview unavailable: ${response.status}`);
|
|
213
|
+
if (response.headers.get("content-type")?.includes("application/json")) {
|
|
214
|
+
const data = await response.json();
|
|
215
|
+
if (typeof data.html !== "string")
|
|
216
|
+
throw new Error("Preview unavailable");
|
|
217
|
+
present(data.html);
|
|
218
|
+
}
|
|
219
|
+
else {
|
|
220
|
+
const parsed = new DOMParser().parseFromString(await response.text(), "text/html");
|
|
221
|
+
present((parsed.querySelector(".preview-content, main") ?? parsed.body).innerHTML);
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
else if (network && /^https?:$/.test(url.protocol)) {
|
|
225
|
+
// shortcut: Some sites hide frame denials; retain the source label as a fallback.
|
|
226
|
+
frame.sandbox.add("allow-scripts");
|
|
227
|
+
frame.src = url.href;
|
|
228
|
+
frame.onerror = () => {
|
|
229
|
+
if (!signal.aborted) {
|
|
230
|
+
frame.replaceWith(status);
|
|
231
|
+
status.textContent = t("Preview unavailable");
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
status.replaceWith(frame);
|
|
235
|
+
position();
|
|
236
|
+
}
|
|
237
|
+
else
|
|
238
|
+
throw new Error("Offline preview unavailable");
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
if (!signal.aborted && popup === host) {
|
|
242
|
+
status.textContent = t("Preview unavailable");
|
|
243
|
+
position();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const previewTarget = (event) => {
|
|
248
|
+
const target = event.target instanceof Element
|
|
249
|
+
? event.target.closest("a[href], .subformat-card-open, [data-subformat-record], [data-resource-source]")
|
|
250
|
+
: null;
|
|
251
|
+
if (!target?.closest("main") ||
|
|
252
|
+
target.closest(".link-preview, dialog, .pane-actions, .page-actions, .resource-toolbar, .res-crumbs, .codeblk-head, .cm-editor, #file-editor, [contenteditable]:not([contenteditable=false])") ||
|
|
253
|
+
target.matches("[download], [data-resource-download]"))
|
|
254
|
+
return;
|
|
255
|
+
return target;
|
|
256
|
+
};
|
|
257
|
+
const begin = (target) => {
|
|
258
|
+
close();
|
|
259
|
+
active = target;
|
|
260
|
+
title = target.getAttribute("title");
|
|
261
|
+
target.removeAttribute("title");
|
|
262
|
+
};
|
|
263
|
+
const enter = (event) => {
|
|
264
|
+
if (restoringFocus ||
|
|
265
|
+
press ||
|
|
266
|
+
popup instanceof HTMLDialogElement ||
|
|
267
|
+
window.getSelection()?.isCollapsed === false)
|
|
268
|
+
return;
|
|
269
|
+
if (event instanceof PointerEvent &&
|
|
270
|
+
(event.pointerType !== "mouse" ||
|
|
271
|
+
event.buttons ||
|
|
272
|
+
!matchMedia("(hover: hover)").matches))
|
|
273
|
+
return;
|
|
274
|
+
const target = previewTarget(event);
|
|
275
|
+
if (!target)
|
|
276
|
+
return;
|
|
277
|
+
if (event.type === "focusin" && !target.matches(":focus-visible"))
|
|
278
|
+
return;
|
|
279
|
+
if (target === active) {
|
|
280
|
+
clearTimeout(closeTimer);
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
begin(target);
|
|
284
|
+
if (event instanceof PointerEvent)
|
|
285
|
+
hoverPoint = { x: event.clientX, y: event.clientY };
|
|
286
|
+
timer = setTimeout(() => void show(target), 650);
|
|
287
|
+
};
|
|
288
|
+
document.addEventListener("pointerover", enter);
|
|
289
|
+
document.addEventListener("focusin", enter);
|
|
290
|
+
document.addEventListener("pointerdown", (event) => {
|
|
291
|
+
suppressClick = false;
|
|
292
|
+
if (popup instanceof HTMLDialogElement)
|
|
293
|
+
return;
|
|
294
|
+
close();
|
|
295
|
+
if (!event.isPrimary ||
|
|
296
|
+
event.button !== 0 ||
|
|
297
|
+
!["touch", "pen"].includes(event.pointerType))
|
|
298
|
+
return;
|
|
299
|
+
const target = previewTarget(event);
|
|
300
|
+
if (!target || window.getSelection()?.isCollapsed === false)
|
|
301
|
+
return;
|
|
302
|
+
begin(target);
|
|
303
|
+
target.dataset.linkPreviewPress = "";
|
|
304
|
+
press = { id: event.pointerId, x: event.clientX, y: event.clientY };
|
|
305
|
+
timer = setTimeout(() => void show(target, true), 500);
|
|
306
|
+
}, true);
|
|
307
|
+
document.addEventListener("pointermove", (event) => {
|
|
308
|
+
if (!active || popup)
|
|
309
|
+
return;
|
|
310
|
+
if (press) {
|
|
311
|
+
if (event.pointerId === press.id &&
|
|
312
|
+
Math.hypot(event.clientX - press.x, event.clientY - press.y) > 10)
|
|
313
|
+
close();
|
|
314
|
+
}
|
|
315
|
+
else if (hoverPoint && event.pointerType === "mouse") {
|
|
316
|
+
if (event.buttons) {
|
|
317
|
+
close();
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
if (Math.hypot(event.clientX - hoverPoint.x, event.clientY - hoverPoint.y) < 4)
|
|
321
|
+
return;
|
|
322
|
+
hoverPoint = { x: event.clientX, y: event.clientY };
|
|
323
|
+
clearTimeout(timer);
|
|
324
|
+
const target = active;
|
|
325
|
+
timer = setTimeout(() => void show(target), 650);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
for (const type of ["pointerup", "pointercancel"])
|
|
329
|
+
document.addEventListener(type, (event) => {
|
|
330
|
+
if (event.pointerId !== press?.id)
|
|
331
|
+
return;
|
|
332
|
+
if (!(popup instanceof HTMLDialogElement))
|
|
333
|
+
close();
|
|
334
|
+
press = undefined;
|
|
335
|
+
});
|
|
336
|
+
document.addEventListener("contextmenu", (event) => {
|
|
337
|
+
if ((press || suppressClick) &&
|
|
338
|
+
event.target instanceof Node &&
|
|
339
|
+
active?.contains(event.target))
|
|
340
|
+
event.preventDefault();
|
|
341
|
+
});
|
|
342
|
+
document.addEventListener("pointerout", (event) => {
|
|
343
|
+
if (!active || press || popup instanceof HTMLDialogElement || event.pointerType !== "mouse")
|
|
344
|
+
return;
|
|
345
|
+
const next = event.relatedTarget;
|
|
346
|
+
if (next instanceof Node && (active.contains(next) || popup?.contains(next))) {
|
|
347
|
+
clearTimeout(closeTimer);
|
|
348
|
+
return;
|
|
349
|
+
}
|
|
350
|
+
clearTimeout(timer);
|
|
351
|
+
clearTimeout(closeTimer);
|
|
352
|
+
if (popup)
|
|
353
|
+
closeTimer = setTimeout(close, 150);
|
|
354
|
+
else
|
|
355
|
+
close();
|
|
356
|
+
});
|
|
357
|
+
document.addEventListener("focusout", (event) => {
|
|
358
|
+
if (event.target === active && !(popup instanceof HTMLDialogElement))
|
|
359
|
+
close();
|
|
360
|
+
});
|
|
361
|
+
document.addEventListener("keydown", (event) => {
|
|
362
|
+
if (event.key === "Escape")
|
|
363
|
+
close();
|
|
364
|
+
});
|
|
365
|
+
window.addEventListener("click", (event) => {
|
|
366
|
+
if (suppressClick && event.detail !== 0) {
|
|
367
|
+
suppressClick = false;
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
event.stopImmediatePropagation();
|
|
370
|
+
}
|
|
371
|
+
else if (!(event.target instanceof Node && popup?.contains(event.target)))
|
|
372
|
+
close();
|
|
373
|
+
}, true);
|
|
374
|
+
document.addEventListener("scroll", () => {
|
|
375
|
+
if (!(popup instanceof HTMLDialogElement))
|
|
376
|
+
close();
|
|
377
|
+
}, true);
|
|
378
|
+
document.addEventListener("selectionchange", () => {
|
|
379
|
+
if (window.getSelection()?.isCollapsed === false && !(popup instanceof HTMLDialogElement))
|
|
380
|
+
close();
|
|
381
|
+
});
|
|
382
|
+
document.addEventListener("dragstart", close);
|
|
383
|
+
window.addEventListener("resize", close);
|
|
384
|
+
document.addEventListener("docs:page-shown", close);
|
|
385
|
+
}
|