parent
91c93322b3
commit
377c71b97a
@ -1,58 +1,57 @@
|
||||
function wackyPatch(parentObj, name, patches) {
|
||||
if (typeof parentObj === "string") {
|
||||
//assume parentObj and name are switched around (for backcompat/convienence)
|
||||
const tmp = parentObj
|
||||
parentObj = name
|
||||
name = tmp
|
||||
}
|
||||
const injId = Symbol()
|
||||
const before = patches["before"];
|
||||
if (typeof parentObj === "string") {
|
||||
//assume parentObj and name are switched around (for backcompat/convienence)
|
||||
const tmp = parentObj;
|
||||
parentObj = name;
|
||||
name = tmp;
|
||||
}
|
||||
const injId = Symbol();
|
||||
const before = patches["before"];
|
||||
const instead = patches["instead"];
|
||||
const after = patches["after"];
|
||||
const after = patches["after"];
|
||||
const handler = {
|
||||
apply: (target, thisArg, [ctx, args]) => {
|
||||
if (before !== undefined) before.apply(ctx, [args]);
|
||||
const res = (patches["instead"] !== undefined) ? instead.apply(ctx, [args, target.bind(ctx)]) : target.apply(ctx, args)
|
||||
if (after === undefined) return res
|
||||
const res =
|
||||
patches["instead"] !== undefined
|
||||
? instead.apply(ctx, [args, target.bind(ctx)])
|
||||
: target.apply(ctx, args);
|
||||
if (after === undefined) return res;
|
||||
return after.apply(ctx, [args, res]);
|
||||
}
|
||||
};
|
||||
const prox = new Proxy(parentObj[name], handler);
|
||||
const orig = parentObj[name];
|
||||
parentObj[name] = function() {
|
||||
parentObj[name] = function () {
|
||||
return prox(this, arguments);
|
||||
};
|
||||
const unpatch = () => {
|
||||
parentObj[name] = orig;
|
||||
}
|
||||
};
|
||||
parentObj[injId] = {
|
||||
name: name,
|
||||
orig: orig,
|
||||
name: name,
|
||||
orig: orig,
|
||||
unpatch: unpatch
|
||||
};
|
||||
return unpatch;
|
||||
}
|
||||
|
||||
function before(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {before: func})
|
||||
return wackyPatch(parentObj, name, { before: func });
|
||||
}
|
||||
|
||||
function instead(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {instead: func})
|
||||
return wackyPatch(parentObj, name, { instead: func });
|
||||
}
|
||||
|
||||
function after(parentObj, name, func) {
|
||||
return wackyPatch(parentObj, name, {after: func})
|
||||
return wackyPatch(parentObj, name, { after: func });
|
||||
}
|
||||
|
||||
export {
|
||||
instead,
|
||||
before,
|
||||
after
|
||||
}
|
||||
export { instead, before, after };
|
||||
|
||||
export default {
|
||||
instead,
|
||||
before,
|
||||
after
|
||||
}
|
||||
instead,
|
||||
before,
|
||||
after
|
||||
};
|
||||
|
@ -1,77 +1,75 @@
|
||||
import webpack from "../webpack"
|
||||
import { React } from "../common"
|
||||
import webpack from "../webpack";
|
||||
import { React } from "../common";
|
||||
|
||||
const { findByProps, findByDisplayName, findByDisplayNameAll } = webpack
|
||||
const { findByProps, findByDisplayName, findByDisplayNameAll } = webpack;
|
||||
|
||||
const { openModal } = findByProps("openModalLazy")
|
||||
const Colors = findByProps("button", "colorRed")
|
||||
const ConfirmModal = findByDisplayName("ConfirmModal")
|
||||
const Markdown = findByDisplayNameAll("Markdown")[1]
|
||||
const { openModal } = findByProps("openModalLazy");
|
||||
const Colors = findByProps("button", "colorRed");
|
||||
const ConfirmModal = findByDisplayName("ConfirmModal");
|
||||
const Markdown = findByDisplayNameAll("Markdown")[1];
|
||||
|
||||
function rawOpenConfirmModal(component, props, insideProps, insideContent) {
|
||||
if (insideProps === undefined) {
|
||||
insideProps = {}
|
||||
}
|
||||
if (insideContent === undefined) {
|
||||
insideContent = ""
|
||||
}
|
||||
let confirmed;
|
||||
openModal((e) => {
|
||||
if (e.transitionState === 3) {
|
||||
return false //TODO: the fuck does this do?
|
||||
}
|
||||
if (insideProps === undefined) {
|
||||
insideProps = {};
|
||||
}
|
||||
if (insideContent === undefined) {
|
||||
insideContent = "";
|
||||
}
|
||||
let confirmed;
|
||||
openModal((e) => {
|
||||
if (e.transitionState === 3) {
|
||||
return false; //TODO: the fuck does this do?
|
||||
}
|
||||
|
||||
return (
|
||||
<ConfirmModal
|
||||
transitionState={e.transitionState}
|
||||
onClose = {() => confirmed = false}
|
||||
onCancel = {() => confirmed = false & e.onClose()}
|
||||
onConfirm = {() => confirmed = true & e.onClose()}
|
||||
{...props}
|
||||
>
|
||||
<component {...insideProps}>{insideContent}</component>
|
||||
</ConfirmModal>
|
||||
)
|
||||
})
|
||||
while (confirmed === undefined) {
|
||||
|
||||
}
|
||||
return confirmed
|
||||
return (
|
||||
<ConfirmModal
|
||||
transitionState={e.transitionState}
|
||||
onClose={() => (confirmed = false)}
|
||||
onCancel={() => (confirmed = false & e.onClose())}
|
||||
onConfirm={() => (confirmed = true & e.onClose())}
|
||||
{...props}
|
||||
>
|
||||
<component {...insideProps}>{insideContent}</component>
|
||||
</ConfirmModal>
|
||||
);
|
||||
});
|
||||
while (confirmed === undefined) {}
|
||||
return confirmed;
|
||||
}
|
||||
|
||||
function openConfirmModal(content, type, opts) {
|
||||
let buttonColor;
|
||||
if (!!opts.color) {
|
||||
buttonColor = opts.color
|
||||
} else {
|
||||
switch (type) {
|
||||
case "danger":
|
||||
buttonColor = Colors.colorRed
|
||||
break
|
||||
case "confirm":
|
||||
buttonColor = Colors.colorGreen
|
||||
break
|
||||
default:
|
||||
buttonColor = Colors.colorBrandNew
|
||||
break
|
||||
}
|
||||
}
|
||||
return rawOpenConfirmModal(
|
||||
Markdown,
|
||||
{
|
||||
header: opts.header ?? "Default Modal Header",
|
||||
confirmText: opts.confirmText ?? "Confirm",
|
||||
cancelText: opts.cancelText ?? "Cancel",
|
||||
confirmButtonColor: buttonColor
|
||||
},
|
||||
{
|
||||
editable: false
|
||||
},
|
||||
content ?? "Default modal content"
|
||||
)
|
||||
let buttonColor;
|
||||
if (!!opts.color) {
|
||||
buttonColor = opts.color;
|
||||
} else {
|
||||
switch (type) {
|
||||
case "danger":
|
||||
buttonColor = Colors.colorRed;
|
||||
break;
|
||||
case "confirm":
|
||||
buttonColor = Colors.colorGreen;
|
||||
break;
|
||||
default:
|
||||
buttonColor = Colors.colorBrandNew;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rawOpenConfirmModal(
|
||||
Markdown,
|
||||
{
|
||||
header: opts.header ?? "Default Modal Header",
|
||||
confirmText: opts.confirmText ?? "Confirm",
|
||||
cancelText: opts.cancelText ?? "Cancel",
|
||||
confirmButtonColor: buttonColor
|
||||
},
|
||||
{
|
||||
editable: false
|
||||
},
|
||||
content ?? "Default modal content"
|
||||
);
|
||||
}
|
||||
|
||||
export default {
|
||||
rawOpenConfirmModal,
|
||||
openConfirmModal
|
||||
}
|
||||
rawOpenConfirmModal,
|
||||
openConfirmModal
|
||||
};
|
||||
|
Loading…
Reference in new issue