@mixd-id/web-scaffold 0.2.250801014 → 0.2.260801002
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -1
- package/docs/components/AIDashboard.md +117 -32
- package/docs/components/Alert.md +3 -1
- package/docs/components/Card.md +5 -0
- package/docs/components/PivotList.md +207 -0
- package/docs/components/Textbox.md +20 -1
- package/docs/components/Tooltip.md +148 -0
- package/package.json +17 -61
- package/src/components/AIChat.vue +14 -5
- package/src/components/AIChatItem.vue +34 -3
- package/src/components/AIDashboard.vue +144 -98
- package/src/components/Alert.vue +58 -35
- package/src/components/Card.vue +55 -6
- package/src/components/Carousel.vue +1 -1
- package/src/{widgets → components}/CartSetting.vue +1 -0
- package/src/components/Chart.vue +2 -2
- package/src/components/Checkbox.vue +22 -24
- package/src/components/CodeEditor.vue +2 -0
- package/src/{widgets → components}/CollapsiblePanelSetting.vue +1 -0
- package/src/components/ColorPicker.vue +2 -2
- package/src/{widgets → components}/ComponentSetting2.vue +1 -1
- package/src/components/Confirm.vue +2 -0
- package/src/{widgets → components}/ContactForm.vue +1 -1
- package/src/components/CopyToClipboard.vue +0 -1
- package/src/components/Datepicker.vue +2 -0
- package/src/components/Datetimepicker.vue +1 -1
- package/src/components/Dropdown.vue +1 -1
- package/src/{widgets → components}/FeatureList.vue +1 -1
- package/src/components/Gmaps.vue +1 -1
- package/src/{widgets → components}/IconList.vue +1 -1
- package/src/components/Image.vue +1 -1
- package/src/components/ImagePreview.vue +32 -51
- package/src/components/List.vue +45 -8
- package/src/components/MarkdownEdit.vue +1 -1
- package/src/components/MarkdownPreview.vue +4 -1
- package/src/{widgets → components}/MenuItem1Setting.vue +1 -0
- package/src/components/Metric.vue +30 -7
- package/src/components/MultiDropdown.vue +3 -1
- package/src/{widgets → components}/MultiValueSetting.vue +2 -2
- package/src/{widgets → components}/MultiValueSetting2.vue +2 -2
- package/src/components/OTPField.vue +3 -1
- package/src/components/PivotList.vue +1239 -0
- package/src/{widgets → components}/PresetBar.vue +1 -1
- package/src/components/PresetSelectorFilterItem.vue +1 -1
- package/src/components/Radio.vue +1 -1
- package/src/{widgets → components}/Share.vue +1 -1
- package/src/components/SvgEditor.vue +1 -1
- package/src/components/Switch.vue +1 -1
- package/src/components/TextWithTag.vue +2 -2
- package/src/components/Textbox.vue +63 -5
- package/src/components/Toast.vue +2 -1
- package/src/components/Tooltip.vue +626 -0
- package/src/components/VirtualGrid.vue +2 -2
- package/src/components/VirtualTable.vue +4 -3
- package/src/{widgets → components}/WebDatasourceSelector.vue +2 -0
- package/src/{widgets → components}/WebLayoutSelector.vue +1 -1
- package/src/directives/tooltip.js +131 -0
- package/src/index.js +11 -235
- package/src/themes/default/index.js +16 -0
- package/src/utils/ai-dashboard.js +163 -38
- package/src/utils/helpers.mjs +52 -5
- package/src/utils/list.mjs +4 -1
- package/src/utils/pivot-formula.mjs +358 -0
- package/src/utils/pivot-list.mjs +557 -0
- package/src/utils/tooltip.mjs +243 -0
- package/src/utils/wss.js +26 -6
- package/src/utils/wss.mjs +29 -2
- /package/src/{widgets → components}/AhrefSetting.vue +0 -0
- /package/src/{widgets → components}/ArticleSetting.vue +0 -0
- /package/src/{widgets → components}/BackgroundColorSetting.vue +0 -0
- /package/src/{widgets → components}/BlockSetting.vue +0 -0
- /package/src/{widgets → components}/BorderColorSetting.vue +0 -0
- /package/src/{widgets → components}/ButtonSetting.vue +0 -0
- /package/src/{widgets → components}/CarouselSetting.vue +0 -0
- /package/src/{widgets → components}/ColumnSelector.vue +0 -0
- /package/src/{widgets → components}/ComponentSetting.vue +0 -0
- /package/src/{widgets → components}/ContactFormSetting.vue +0 -0
- /package/src/{widgets → components}/CountdownSetting.vue +0 -0
- /package/src/{widgets → components}/DataListSetting.vue +0 -0
- /package/src/{widgets → components}/EmbeddedVideo.vue +0 -0
- /package/src/{widgets → components}/EmbeddedVideoSetting.vue +0 -0
- /package/src/{widgets → components}/FAQ.vue +0 -0
- /package/src/{widgets → components}/FAQSetting.vue +0 -0
- /package/src/{widgets → components}/FeatureListSetting.vue +0 -0
- /package/src/{widgets → components}/FlexSetting.vue +0 -0
- /package/src/{widgets → components}/GridSetting.vue +0 -0
- /package/src/{widgets → components}/Header2.vue +0 -0
- /package/src/{widgets → components}/Header2Setting.vue +0 -0
- /package/src/{widgets → components}/IconListSetting.vue +0 -0
- /package/src/{widgets → components}/ImageSetting.vue +0 -0
- /package/src/{widgets → components}/LLMChat.vue +0 -0
- /package/src/{widgets → components}/LinkSetting.vue +0 -0
- /package/src/{widgets → components}/LinkSettingModal.vue +0 -0
- /package/src/{widgets → components}/ModalSetting.vue +0 -0
- /package/src/{widgets → components}/OGSettingModal.vue +0 -0
- /package/src/{widgets → components}/ParagraphSetting.vue +0 -0
- /package/src/{widgets → components}/PositionSetting.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivot.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivotColumnEdit.vue +0 -0
- /package/src/{widgets → components}/PresetBarPivotValueEdit.vue +0 -0
- /package/src/{widgets → components}/PresetSelector.vue +0 -0
- /package/src/{widgets → components}/Review.vue +0 -0
- /package/src/{widgets → components}/ReviewSetting.vue +0 -0
- /package/src/{widgets → components}/SearchModalSetting.vue +0 -0
- /package/src/{widgets → components}/ShareSetting.vue +0 -0
- /package/src/{widgets → components}/SvgSetting.vue +0 -0
- /package/src/{widgets → components}/TableSetting.vue +0 -0
- /package/src/{widgets → components}/TestimonialSetting.vue +0 -0
- /package/src/{widgets → components}/TextBlockSetting.vue +0 -0
- /package/src/{widgets → components}/ThumbnailSetting.vue +0 -0
- /package/src/{widgets → components}/WebComponentSelector.vue +0 -0
- /package/src/{widgets → components}/WebPageBuilder.vue +0 -0
- /package/src/{widgets → components}/YoutubeVideoSetting.vue +0 -0
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
import { createApp, h, reactive } from 'vue'
|
|
2
|
+
|
|
3
|
+
// Shared, singleton tooltip controller.
|
|
4
|
+
//
|
|
5
|
+
// Everything that wants to show a tooltip (the `v-tooltip` directive, the
|
|
6
|
+
// <Tooltip> component, or app code calling showTooltip() directly) writes into
|
|
7
|
+
// `tooltipState`. A single <Tooltip singleton> layer — mounted lazily on the
|
|
8
|
+
// first use — is the only thing that renders it, so at most one tooltip is ever
|
|
9
|
+
// alive in the DOM.
|
|
10
|
+
|
|
11
|
+
export const TOOLTIP_ID = 'mx-tooltip'
|
|
12
|
+
export const TOOLTIP_DELAY = 400 // hover intent before showing
|
|
13
|
+
export const TOOLTIP_HIDE_DELAY = 60 // small grace so a wobbly pointer doesn't flicker
|
|
14
|
+
export const TOOLTIP_GRACE = 320 // moving between neighbours re-shows instantly
|
|
15
|
+
export const TOOLTIP_OFFSET = 8 // gap between anchor and tooltip
|
|
16
|
+
export const TOOLTIP_TOUCH_DELAY = 450 // long-press on touch devices
|
|
17
|
+
export const TOOLTIP_TOUCH_TIMEOUT = 2500
|
|
18
|
+
|
|
19
|
+
export const TOOLTIP_PLACEMENTS = [ 'top', 'bottom', 'left', 'right' ]
|
|
20
|
+
export const TOOLTIP_VARIANTS = [ 'base', 'primary', 'secondary', 'accent', 'danger', 'success' ]
|
|
21
|
+
|
|
22
|
+
const DEFAULTS = {
|
|
23
|
+
text: '',
|
|
24
|
+
title: '',
|
|
25
|
+
shortcut: '',
|
|
26
|
+
placement: 'top',
|
|
27
|
+
variant: 'base',
|
|
28
|
+
arrow: true,
|
|
29
|
+
offset: TOOLTIP_OFFSET,
|
|
30
|
+
maxWidth: null,
|
|
31
|
+
delay: null
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
export const tooltipState = reactive({
|
|
35
|
+
...DEFAULTS,
|
|
36
|
+
open: false,
|
|
37
|
+
anchor: null
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Accepts the shorthand forms a tooltip can be declared with and returns a full
|
|
42
|
+
* options object: `'Save'`, `{ text: 'Save', placement: 'bottom' }`.
|
|
43
|
+
*/
|
|
44
|
+
export const normalizeTooltipOptions = (value, defaults) => {
|
|
45
|
+
|
|
46
|
+
const given = value === null || value === undefined ? {} :
|
|
47
|
+
(typeof value === 'object' ? value : { text: String(value) })
|
|
48
|
+
|
|
49
|
+
const opts = { ...DEFAULTS, ...(defaults || {}), ...given }
|
|
50
|
+
|
|
51
|
+
opts.text = opts.text === null || opts.text === undefined ? '' : String(opts.text)
|
|
52
|
+
if(!TOOLTIP_PLACEMENTS.includes(opts.placement)) opts.placement = DEFAULTS.placement
|
|
53
|
+
if(!TOOLTIP_VARIANTS.includes(opts.variant)) opts.variant = DEFAULTS.variant
|
|
54
|
+
|
|
55
|
+
return opts
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* True when the element got focus from the keyboard, so a mouse click doesn't
|
|
60
|
+
* leave a tooltip hanging around. Browsers without `:focus-visible` show it.
|
|
61
|
+
*/
|
|
62
|
+
export const isKeyboardFocus = (el) => {
|
|
63
|
+
|
|
64
|
+
if(!el || typeof el.matches !== 'function') return true
|
|
65
|
+
|
|
66
|
+
try{
|
|
67
|
+
return el.matches(':focus-visible')
|
|
68
|
+
}
|
|
69
|
+
catch(e){
|
|
70
|
+
return true
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
let layer = null
|
|
75
|
+
let showTimer = null
|
|
76
|
+
let hideTimer = null
|
|
77
|
+
let pendingAnchor = null
|
|
78
|
+
let lastHiddenAt = 0
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Mounts the singleton <Tooltip> layer once, on the client only. Safe to call
|
|
82
|
+
* as often as you like — subsequent calls return the same promise.
|
|
83
|
+
*/
|
|
84
|
+
export const mountTooltipLayer = () => {
|
|
85
|
+
|
|
86
|
+
if(typeof document === 'undefined') return null
|
|
87
|
+
if(layer) return layer
|
|
88
|
+
|
|
89
|
+
// Imported lazily: it keeps Tooltip.vue out of the initial chunk and breaks
|
|
90
|
+
// the component <-> controller import cycle.
|
|
91
|
+
layer = import('../components/Tooltip.vue').then((module) => {
|
|
92
|
+
|
|
93
|
+
const host = document.createElement('div')
|
|
94
|
+
host.setAttribute('data-tooltip-layer', '')
|
|
95
|
+
document.body.appendChild(host)
|
|
96
|
+
|
|
97
|
+
const app = createApp({ render: () => h(module.default, { singleton: true }) })
|
|
98
|
+
app.mount(host)
|
|
99
|
+
|
|
100
|
+
return app
|
|
101
|
+
})
|
|
102
|
+
|
|
103
|
+
return layer
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const describe = (el, on) => {
|
|
107
|
+
if(!el || typeof el.setAttribute !== 'function') return
|
|
108
|
+
if(on) el.setAttribute('aria-describedby', TOOLTIP_ID)
|
|
109
|
+
else if(el.getAttribute('aria-describedby') === TOOLTIP_ID) el.removeAttribute('aria-describedby')
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
const commit = (el, opts) => {
|
|
113
|
+
describe(tooltipState.anchor, false)
|
|
114
|
+
Object.assign(tooltipState, opts, { open: true, anchor: el })
|
|
115
|
+
describe(el, true)
|
|
116
|
+
pendingAnchor = null
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* @param {Element|{ getBoundingClientRect: function }} el - the anchor
|
|
121
|
+
* @param {object|string} options - tooltip options (see normalizeTooltipOptions)
|
|
122
|
+
*/
|
|
123
|
+
export const showTooltip = (el, options) => {
|
|
124
|
+
|
|
125
|
+
if(typeof document === 'undefined' || !el) return
|
|
126
|
+
|
|
127
|
+
const opts = normalizeTooltipOptions(options)
|
|
128
|
+
if(!opts.text && !opts.title) return
|
|
129
|
+
|
|
130
|
+
mountTooltipLayer()
|
|
131
|
+
|
|
132
|
+
clearTimeout(hideTimer)
|
|
133
|
+
clearTimeout(showTimer)
|
|
134
|
+
hideTimer = null
|
|
135
|
+
|
|
136
|
+
// Already showing something, or the previous tooltip just closed: skip the
|
|
137
|
+
// hover-intent delay so scanning across a toolbar feels immediate.
|
|
138
|
+
const warm = tooltipState.open || (Date.now() - lastHiddenAt) < TOOLTIP_GRACE
|
|
139
|
+
const delay = warm ? 0 : (opts.delay === null || opts.delay === undefined ? TOOLTIP_DELAY : opts.delay)
|
|
140
|
+
|
|
141
|
+
if(delay > 0){
|
|
142
|
+
pendingAnchor = el
|
|
143
|
+
showTimer = setTimeout(() => commit(el, opts), delay)
|
|
144
|
+
}
|
|
145
|
+
else{
|
|
146
|
+
commit(el, opts)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
const close = () => {
|
|
151
|
+
describe(tooltipState.anchor, false)
|
|
152
|
+
tooltipState.open = false
|
|
153
|
+
tooltipState.anchor = null
|
|
154
|
+
lastHiddenAt = Date.now()
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* Hides the tooltip. When `el` is given it is only hidden if that element is
|
|
159
|
+
* the one currently owning it (so a stale mouseleave can't close a newer tip).
|
|
160
|
+
*/
|
|
161
|
+
export const hideTooltip = (el) => {
|
|
162
|
+
|
|
163
|
+
if(el && pendingAnchor && pendingAnchor !== el && tooltipState.anchor !== el) return
|
|
164
|
+
|
|
165
|
+
if(!el || pendingAnchor === el){
|
|
166
|
+
clearTimeout(showTimer)
|
|
167
|
+
showTimer = null
|
|
168
|
+
pendingAnchor = null
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if(!tooltipState.open || (el && tooltipState.anchor !== el)) return
|
|
172
|
+
|
|
173
|
+
clearTimeout(hideTimer)
|
|
174
|
+
hideTimer = setTimeout(close, TOOLTIP_HIDE_DELAY)
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/** Hides immediately — used for clicks, scrolling away, Escape. */
|
|
178
|
+
export const hideTooltipNow = (el) => {
|
|
179
|
+
|
|
180
|
+
if(el && tooltipState.anchor !== el && pendingAnchor !== el) return
|
|
181
|
+
|
|
182
|
+
clearTimeout(showTimer)
|
|
183
|
+
clearTimeout(hideTimer)
|
|
184
|
+
showTimer = hideTimer = pendingAnchor = null
|
|
185
|
+
|
|
186
|
+
if(tooltipState.open) close()
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
// --- disabled anchors -------------------------------------------------------
|
|
190
|
+
// Disabled form controls never fire mouse events, so `v-tooltip` on a disabled
|
|
191
|
+
// <button> (e.g. Button's `disabledText`) would silently do nothing. For those
|
|
192
|
+
// anchors only, we hit-test the pointer against the document instead.
|
|
193
|
+
|
|
194
|
+
const disabledTargets = new Map()
|
|
195
|
+
let disabledHovered = null
|
|
196
|
+
let disabledProbeAt = 0
|
|
197
|
+
|
|
198
|
+
const onDocumentPointerMove = (e) => {
|
|
199
|
+
|
|
200
|
+
if(disabledTargets.size < 1) return
|
|
201
|
+
if(e.timeStamp - disabledProbeAt < 60) return
|
|
202
|
+
disabledProbeAt = e.timeStamp
|
|
203
|
+
|
|
204
|
+
let node = document.elementFromPoint(e.clientX, e.clientY)
|
|
205
|
+
let match = null
|
|
206
|
+
|
|
207
|
+
while(node && node !== document.body){
|
|
208
|
+
if(disabledTargets.has(node)){
|
|
209
|
+
match = node
|
|
210
|
+
break
|
|
211
|
+
}
|
|
212
|
+
node = node.parentElement
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
if(match === disabledHovered) return
|
|
216
|
+
|
|
217
|
+
if(disabledHovered) disabledTargets.get(disabledHovered)?.hide()
|
|
218
|
+
disabledHovered = match
|
|
219
|
+
if(match) disabledTargets.get(match).show()
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
export const registerDisabledTarget = (el, handlers) => {
|
|
223
|
+
|
|
224
|
+
if(typeof document === 'undefined') return
|
|
225
|
+
|
|
226
|
+
if(disabledTargets.size < 1){
|
|
227
|
+
document.addEventListener('pointermove', onDocumentPointerMove, { passive: true })
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
disabledTargets.set(el, handlers)
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export const unregisterDisabledTarget = (el) => {
|
|
234
|
+
|
|
235
|
+
if(!disabledTargets.has(el)) return
|
|
236
|
+
|
|
237
|
+
disabledTargets.delete(el)
|
|
238
|
+
if(disabledHovered === el) disabledHovered = null
|
|
239
|
+
|
|
240
|
+
if(disabledTargets.size < 1 && typeof document !== 'undefined'){
|
|
241
|
+
document.removeEventListener('pointermove', onDocumentPointerMove)
|
|
242
|
+
}
|
|
243
|
+
}
|
package/src/utils/wss.js
CHANGED
|
@@ -120,12 +120,14 @@ class WSS extends EventEmitter2{
|
|
|
120
120
|
this._debugIds[socket.id] = {}
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
const debug = !!this._debugIds[socket.id]
|
|
124
|
+
|
|
123
125
|
let subscriber
|
|
124
126
|
|
|
125
127
|
const listener = (message) => {
|
|
126
128
|
const { model, event, items } = JSON.parse(message)
|
|
127
|
-
this.toBinaryData({ data:{ model, event, items } },
|
|
128
|
-
.then(data => socket.send(data))
|
|
129
|
+
this.toBinaryData({ data:{ model, event, items } }, debug)
|
|
130
|
+
.then(data => socket.send(data, { binary: !debug }))
|
|
129
131
|
}
|
|
130
132
|
|
|
131
133
|
socket.leave = (channel) => {
|
|
@@ -157,6 +159,22 @@ class WSS extends EventEmitter2{
|
|
|
157
159
|
}
|
|
158
160
|
}
|
|
159
161
|
|
|
162
|
+
// One frame straight to this socket, outside the request/reply pairing.
|
|
163
|
+
// Used for partial replies (a model streaming its answer): the frames
|
|
164
|
+
// carry the caller's own `_streamId`, never a `_requestId`, so a client
|
|
165
|
+
// that did not ask for them cannot mistake one for a finished reply.
|
|
166
|
+
socket.push = async (obj) => {
|
|
167
|
+
if(socket.readyState !== 1) return
|
|
168
|
+
|
|
169
|
+
try{
|
|
170
|
+
socket.send(await this.toBinaryData(obj, debug), { binary: !debug })
|
|
171
|
+
}
|
|
172
|
+
catch(e){
|
|
173
|
+
// A caller streaming into a socket that has gone away is ordinary.
|
|
174
|
+
console.error('[WSS] push failed', e.message)
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
|
|
160
178
|
socket.on('message', async (binaryData) => {
|
|
161
179
|
if(!socket.isAuth) return
|
|
162
180
|
|
|
@@ -175,7 +193,7 @@ class WSS extends EventEmitter2{
|
|
|
175
193
|
this._retryCount = 0
|
|
176
194
|
}
|
|
177
195
|
else if(ping){
|
|
178
|
-
socket.send(await this.toBinaryData({ pong: 1 },
|
|
196
|
+
socket.send(await this.toBinaryData({ pong: 1 }, debug), { binary: !debug })
|
|
179
197
|
}
|
|
180
198
|
else{
|
|
181
199
|
let status = 200
|
|
@@ -206,7 +224,7 @@ class WSS extends EventEmitter2{
|
|
|
206
224
|
_requestId,
|
|
207
225
|
status,
|
|
208
226
|
data
|
|
209
|
-
},
|
|
227
|
+
}, debug), { binary: !debug })
|
|
210
228
|
}
|
|
211
229
|
});
|
|
212
230
|
|
|
@@ -220,6 +238,8 @@ class WSS extends EventEmitter2{
|
|
|
220
238
|
|
|
221
239
|
this._sockets.splice(this._sockets.indexOf(socket), 1)
|
|
222
240
|
|
|
241
|
+
delete this._debugIds[socket.id]
|
|
242
|
+
|
|
223
243
|
});
|
|
224
244
|
|
|
225
245
|
const token = req.headers['sec-websocket-protocol'];
|
|
@@ -233,7 +253,7 @@ class WSS extends EventEmitter2{
|
|
|
233
253
|
}
|
|
234
254
|
|
|
235
255
|
socket.isAuth = true
|
|
236
|
-
socket.send(await this.toBinaryData({ auth:true },
|
|
256
|
+
socket.send(await this.toBinaryData({ auth:true }, debug), { binary: !debug })
|
|
237
257
|
|
|
238
258
|
subscriber = this._client.duplicate()
|
|
239
259
|
await subscriber.connect()
|
|
@@ -245,7 +265,7 @@ class WSS extends EventEmitter2{
|
|
|
245
265
|
if(this._opt.ping !== false){
|
|
246
266
|
|
|
247
267
|
const ping = async() => {
|
|
248
|
-
socket.send(await this.toBinaryData({ ping:1 },
|
|
268
|
+
socket.send(await this.toBinaryData({ ping:1 }, debug), { binary: !debug })
|
|
249
269
|
socket.pinging = true
|
|
250
270
|
|
|
251
271
|
setTimeout(() => {
|
package/src/utils/wss.mjs
CHANGED
|
@@ -45,6 +45,8 @@ class WSS extends EventEmitter2{
|
|
|
45
45
|
_counter = 0
|
|
46
46
|
_callbacks = {}
|
|
47
47
|
_pendingSend = []
|
|
48
|
+
// Partial-reply handlers, keyed by the `_streamId` the request carried.
|
|
49
|
+
_streams = {}
|
|
48
50
|
_pinging = false
|
|
49
51
|
_retryCount = 1
|
|
50
52
|
|
|
@@ -78,7 +80,7 @@ class WSS extends EventEmitter2{
|
|
|
78
80
|
}
|
|
79
81
|
|
|
80
82
|
async fromBinaryData(binaryData){
|
|
81
|
-
const encryptedString = new TextDecoder().decode(binaryData)
|
|
83
|
+
const encryptedString = typeof binaryData === 'string' ? binaryData : new TextDecoder().decode(binaryData)
|
|
82
84
|
const decryptedData = this._opt.key && !this._opt.debug ?
|
|
83
85
|
CryptoJS.AES.decrypt(encryptedString, this._opt.key).toString(CryptoJS.enc.Utf8) :
|
|
84
86
|
encryptedString;
|
|
@@ -122,11 +124,23 @@ class WSS extends EventEmitter2{
|
|
|
122
124
|
this.flushPending()
|
|
123
125
|
this.emit('connect', reconnect, [])
|
|
124
126
|
}
|
|
127
|
+
// A partial reply, while the request it belongs to is still open. Matched
|
|
128
|
+
// on the caller's own `_streamId` rather than `_requestId`, so a frame
|
|
129
|
+
// like this can never be mistaken for the finished reply.
|
|
130
|
+
else if(obj.stream){
|
|
131
|
+
const onStream = this._streams[obj.streamId]
|
|
132
|
+
|
|
133
|
+
if(onStream){
|
|
134
|
+
try{ onStream(obj.delta ?? '', obj) }
|
|
135
|
+
catch(e){ console.error('onStream', e) }
|
|
136
|
+
}
|
|
137
|
+
}
|
|
125
138
|
else if(_requestId){
|
|
126
139
|
if(this._callbacks[_requestId] && this._instance.readyState === 1){
|
|
127
|
-
const { cb, err, path, params, t1 } = this._callbacks[_requestId]
|
|
140
|
+
const { cb, err, path, params, t1, streamId } = this._callbacks[_requestId]
|
|
128
141
|
status === 200 ? cb(data) : err(data)
|
|
129
142
|
delete this._callbacks[_requestId]
|
|
143
|
+
if(streamId) delete this._streams[streamId]
|
|
130
144
|
|
|
131
145
|
if(this._opt.debug){
|
|
132
146
|
status === 200 ?
|
|
@@ -206,6 +220,18 @@ class WSS extends EventEmitter2{
|
|
|
206
220
|
|
|
207
221
|
const _requestId = ++this._counter
|
|
208
222
|
|
|
223
|
+
// Streaming is opt-in per request: the server only sends partial frames
|
|
224
|
+
// when the caller supplied a `_streamId`, so nothing changes for anyone
|
|
225
|
+
// who did not ask — including the native clients.
|
|
226
|
+
const onStream = (override ?? {}).onStream
|
|
227
|
+
let streamId = null
|
|
228
|
+
|
|
229
|
+
if(typeof onStream === 'function'){
|
|
230
|
+
streamId = `s${_requestId}`
|
|
231
|
+
this._streams[streamId] = onStream
|
|
232
|
+
params = { ...(params ?? {}), _streamId: streamId }
|
|
233
|
+
}
|
|
234
|
+
|
|
209
235
|
convertDataUrlObj({
|
|
210
236
|
_requestId,
|
|
211
237
|
path,
|
|
@@ -220,6 +246,7 @@ class WSS extends EventEmitter2{
|
|
|
220
246
|
err,
|
|
221
247
|
path,
|
|
222
248
|
params,
|
|
249
|
+
streamId,
|
|
223
250
|
t1: new Date().getTime()
|
|
224
251
|
}
|
|
225
252
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|