-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
173 changed files
with
2,787 additions
and
2,784 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { startAjaxIntercept } from '@lib/bootstrap'; | ||
export { AJAX_INTERCEPT_MESSAGE_TYPE, type IAjaxInterceptMessage } from '@lib/ajax-intercept.message'; | ||
export { interceptRequest } from '@lib/ajax-intercept-script'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import type { IAjaxInterceptMessage } from './ajax-intercept.message'; | ||
import { AJAX_INTERCEPT_MESSAGE_TYPE } from './ajax-intercept.message'; | ||
|
||
function _interceptRequest(onResponse: (response: any) => void) { | ||
const XHR = XMLHttpRequest; | ||
const _fetch = fetch; | ||
|
||
const onReadyStateChange = async function (this: XMLHttpRequest) { | ||
if (this.readyState === 4) { | ||
onResponse(this.response); | ||
} | ||
}; | ||
// @ts-expect-error | ||
const innerXHR: typeof XMLHttpRequest = function () { | ||
const xhr = new XHR(); | ||
xhr.addEventListener('readystatechange', onReadyStateChange.bind(xhr), false); | ||
return xhr; | ||
}; | ||
innerXHR.prototype = XHR.prototype; | ||
Object.entries(XHR).forEach(([key, val]) => { | ||
// @ts-ignore | ||
innerXHR[key] = val; | ||
}); | ||
|
||
const innerFetch: typeof _fetch = async (resource, initOptions) => { | ||
const getOriginalResponse = () => _fetch(resource, initOptions); | ||
const fetchedResponse = getOriginalResponse(); | ||
|
||
fetchedResponse.then((response) => { | ||
if (response instanceof Response) { | ||
try { | ||
response.clone() | ||
.json() | ||
.then((res) => onResponse(res)) | ||
.catch(() => { | ||
// Do nothing | ||
}); | ||
} catch (err) {} | ||
} | ||
}); | ||
return fetchedResponse; | ||
}; | ||
window.XMLHttpRequest = innerXHR; | ||
window.fetch = innerFetch; | ||
} | ||
|
||
function serializeToJSON(response: unknown) { | ||
try { | ||
return JSON.parse(JSON.stringify(response)); | ||
} catch { | ||
return null; | ||
} | ||
} | ||
|
||
export function interceptRequest() { | ||
_interceptRequest((res) => { | ||
const msg: IAjaxInterceptMessage = { | ||
type: AJAX_INTERCEPT_MESSAGE_TYPE, | ||
response: serializeToJSON(res), | ||
}; | ||
|
||
postMessage(msg); | ||
}); | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
|
||
export const AJAX_INTERCEPT_MESSAGE_TYPE = 'CLIPSHEET_AJAX_INTERCEPT_MESSAGE'; | ||
|
||
export interface IAjaxInterceptMessage { | ||
type: typeof AJAX_INTERCEPT_MESSAGE_TYPE; | ||
response: any; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import type { IAjaxInterceptMessage } from './ajax-intercept.message'; | ||
import { AJAX_INTERCEPT_MESSAGE_TYPE } from './ajax-intercept.message'; | ||
|
||
export function startAjaxIntercept(scriptSrc: string, onMessage: (message: any) => void) { | ||
const script = document.createElement('script'); | ||
script.setAttribute('type', 'text/javascript'); | ||
script.setAttribute('src', scriptSrc); | ||
document.documentElement.appendChild(script); | ||
|
||
const listener = (event: MessageEvent) => { | ||
const message = event.data as IAjaxInterceptMessage; | ||
if (message.type === AJAX_INTERCEPT_MESSAGE_TYPE) { | ||
onMessage(message.response); | ||
} | ||
}; | ||
|
||
window.addEventListener('message', listener); | ||
|
||
return () => [ | ||
window.removeEventListener('message', listener), | ||
document.documentElement.removeChild(script), | ||
]; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
"name": "@univer-clipsheet-core/ajax-intercept", | ||
"version": "0.0.1", | ||
"private": true, | ||
"description": "ajax-intercept code", | ||
"sideEffects": false, | ||
"main": "./dist/index.js", | ||
"module": "./dist/index.mjs", | ||
"types": "./dist/index.d.ts", | ||
"files": [ | ||
"dist/**" | ||
], | ||
"scripts": { | ||
"clean": "rimraf ./dist && rimraf .turbo", | ||
"build": "tsup index.ts --format esm,cjs --dts --external react,chrome", | ||
"dev": "pnpm run build --watch", | ||
"type-check": "tsc --noEmit" | ||
}, | ||
"peerDependencies": { | ||
"@wendellhu/redi": "0.16.1" | ||
}, | ||
"dependencies": { | ||
"@univer-clipsheet-core/shared": "workspace:*" | ||
}, | ||
"devDependencies": { | ||
"@univer-clipsheet-core/tailwindcss-config": "workspace:*", | ||
"@univer-clipsheet-core/tsconfig": "workspace:*" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = { | ||
plugins: { | ||
tailwindcss: {}, | ||
autoprefixer: {}, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"extends": "@univer-clipsheet-core/tsconfig/utils", | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"baseUrl": ".", | ||
"paths": { | ||
"@lib/*": [ | ||
"lib/*" | ||
] | ||
}, | ||
"types": ["chrome"], | ||
"outDir": "dist" | ||
}, | ||
"include": [ | ||
"index.ts", | ||
"lib" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { defineConfig } from 'tsup'; | ||
|
||
export default defineConfig({ | ||
treeshake: true, | ||
format: ['cjs', 'esm'], | ||
dts: true, | ||
external: ['chrome'], | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
export { DrillDownService } from './drill-down.service'; | ||
export * from './drill-down-channel'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.