@dovetail-v2/refine 0.4.2-alpha.0 → 0.4.2-beta.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.
@@ -0,0 +1,216 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const common = require("./common-1eb43414.cjs");
4
+ const eagle = require("@cloudtower/eagle");
5
+ const React = require("react");
6
+ const index = require("./index-31874f77.cjs");
7
+ const buffer = require("buffer");
8
+ require("@xterm/addon-canvas");
9
+ require("@xterm/addon-fit");
10
+ require("@xterm/addon-search");
11
+ require("@xterm/addon-web-links");
12
+ require("@xterm/addon-webgl");
13
+ require("@xterm/xterm");
14
+ require("copy-to-clipboard");
15
+ require("lodash-es");
16
+ require("@cloudtower/icons-react");
17
+ function addParam(url, key, val) {
18
+ let out = url + (url.includes("?") ? "&" : "?");
19
+ if (!Array.isArray(val)) {
20
+ val = [val];
21
+ }
22
+ out += val.map((v) => {
23
+ if (v === null) {
24
+ return `${encodeURIComponent(key)}`;
25
+ } else {
26
+ return `${encodeURIComponent(key)}=${encodeURIComponent(v)}`;
27
+ }
28
+ }).join("&");
29
+ return out;
30
+ }
31
+ function addParams(url, params) {
32
+ if (params && typeof params === "object") {
33
+ Object.keys(params).forEach((key) => {
34
+ url = addParam(url, key, params[key]);
35
+ });
36
+ }
37
+ return url;
38
+ }
39
+ function base64Encode(str, alphabet = "normal") {
40
+ let buf;
41
+ if (str === null || typeof str === "undefined") {
42
+ return str;
43
+ }
44
+ if (typeof buffer.Buffer.from === "function" && buffer.Buffer.from !== Uint8Array.from) {
45
+ buf = buffer.Buffer.from(str);
46
+ } else {
47
+ buf = new buffer.Buffer(str);
48
+ }
49
+ if (alphabet === "url") {
50
+ const m = {
51
+ "+": "-",
52
+ "/": "_"
53
+ };
54
+ return buf.toString("base64").replace(/[+/]|=+$/g, (char) => m[char] || "");
55
+ }
56
+ return buf.toString("base64");
57
+ }
58
+ function base64DecodeToBuffer(str) {
59
+ if (str === null || typeof str === "undefined") {
60
+ return str;
61
+ }
62
+ if (typeof buffer.Buffer.from === "function" && buffer.Buffer.from !== Uint8Array.from) {
63
+ return buffer.Buffer.from(str, "base64");
64
+ } else {
65
+ return new buffer.Buffer(str, "base64");
66
+ }
67
+ }
68
+ function base64Decode(str) {
69
+ return !str ? str : base64DecodeToBuffer(str.replace(/[-_]/g, (char) => char === "-" ? "+" : "/")).toString();
70
+ }
71
+ var OS = /* @__PURE__ */ ((OS2) => {
72
+ OS2["Linux"] = "linux";
73
+ OS2["Windows"] = "windows";
74
+ return OS2;
75
+ })(OS || {});
76
+ const BACKUP_SHELLS = [
77
+ "windows",
78
+ "linux"
79
+ /* Linux */
80
+ ];
81
+ const COMMANDS = {
82
+ [
83
+ "linux"
84
+ /* Linux */
85
+ ]: [
86
+ "/bin/sh",
87
+ "-c",
88
+ 'TERM=xterm-256color; export TERM; [ -x /bin/bash ] && ([ -x /usr/bin/script ] && /usr/bin/script -q -c "/bin/bash" /dev/null || exec /bin/bash) || exec /bin/sh'
89
+ ],
90
+ [
91
+ "windows"
92
+ /* Windows */
93
+ ]: ["cmd"]
94
+ };
95
+ const PodShell = React.forwardRef(
96
+ function PodShell2(props, ref) {
97
+ const { pod, basePath, onSocketStatusChange } = props;
98
+ const id = pod.id;
99
+ const [namespace, name] = React.useMemo(() => id.split("/"), [id]);
100
+ const shellRef = React.useRef(null);
101
+ const errorMsgRef = React.useRef("");
102
+ const [osIndex, setOsIndex] = React.useState(0);
103
+ const [container, setContainer] = React.useState("");
104
+ const containers = React.useMemo(() => {
105
+ var _a, _b;
106
+ return (((_a = pod == null ? void 0 : pod._rawYaml.status) == null ? void 0 : _a.containerStatuses) || []).concat(((_b = pod == null ? void 0 : pod._rawYaml.status) == null ? void 0 : _b.initContainerStatuses) || []).map((containerStatus) => containerStatus.name);
107
+ }, [pod]);
108
+ const url = React.useMemo(() => {
109
+ const os = BACKUP_SHELLS[osIndex];
110
+ const protocol = location.protocol.includes("https") ? "wss" : "ws";
111
+ const url2 = container && os ? addParams(
112
+ `${protocol}://${location.host}${basePath}/api/v1/namespaces/${namespace}/pods/${name}/exec`,
113
+ {
114
+ container,
115
+ stdout: "true",
116
+ stdin: "true",
117
+ stderr: "true",
118
+ tty: "true",
119
+ command: COMMANDS[
120
+ os || "linux"
121
+ /* Linux */
122
+ ]
123
+ }
124
+ ) : "";
125
+ return url2;
126
+ }, [container, name, namespace, osIndex, basePath]);
127
+ const onSocketClose = React.useCallback(
128
+ (socket, term) => {
129
+ var _a, _b;
130
+ if (errorMsgRef.current) {
131
+ if (osIndex + 1 < BACKUP_SHELLS.length) {
132
+ setOsIndex(osIndex + 1);
133
+ } else {
134
+ term == null ? void 0 : term.writeln(`\x1B[38;2;255;82;82m${errorMsgRef.current}`);
135
+ (_a = shellRef.current) == null ? void 0 : _a.setSocketStatus(common.SocketStatus.Disconnected);
136
+ errorMsgRef.current = "";
137
+ }
138
+ } else {
139
+ (_b = shellRef.current) == null ? void 0 : _b.setSocketStatus(common.SocketStatus.Disconnected);
140
+ }
141
+ },
142
+ [osIndex]
143
+ );
144
+ const onSocketMessage = React.useCallback(
145
+ (e, socket, term) => {
146
+ const type = e.data.substr(0, 1);
147
+ const msg = base64Decode(e.data.substr(1));
148
+ if (`${type}` === "1") {
149
+ term == null ? void 0 : term.write(msg);
150
+ } else {
151
+ if (`${type}` === "3") {
152
+ errorMsgRef.current = msg;
153
+ }
154
+ }
155
+ },
156
+ []
157
+ );
158
+ const fit = React.useCallback(({ rows, cols }) => {
159
+ var _a;
160
+ const message = `${"4"}${base64Encode(
161
+ JSON.stringify({
162
+ Width: Math.floor(cols),
163
+ Height: Math.floor(rows)
164
+ })
165
+ )}`;
166
+ (_a = shellRef.current) == null ? void 0 : _a.send(message);
167
+ }, []);
168
+ const encode = React.useCallback((input) => `${"0"}${base64Encode(input)}`, []);
169
+ React.useEffect(() => {
170
+ if (!container && containers.length) {
171
+ setContainer(containers[0]);
172
+ }
173
+ }, [containers, container]);
174
+ React.useImperativeHandle(
175
+ ref,
176
+ () => ({
177
+ getAllTerminalContents: () => {
178
+ var _a;
179
+ return ((_a = shellRef.current) == null ? void 0 : _a.getAllTerminalContents()) || [];
180
+ }
181
+ }),
182
+ []
183
+ );
184
+ return /* @__PURE__ */ common.jsxRuntimeExports.jsx(
185
+ index.Shell,
186
+ {
187
+ ref: shellRef,
188
+ url,
189
+ protocols: "base64.channel.k8s.io",
190
+ encode,
191
+ fit,
192
+ toolbarLeftSlot: /* @__PURE__ */ common.jsxRuntimeExports.jsx(
193
+ eagle.Select,
194
+ {
195
+ input: {
196
+ value: container,
197
+ onChange(value) {
198
+ setContainer(value);
199
+ }
200
+ },
201
+ style: {
202
+ width: "256px"
203
+ },
204
+ size: "small",
205
+ children: containers.map((containerName) => /* @__PURE__ */ common.jsxRuntimeExports.jsx(eagle.AntdOption, { value: containerName, label: containerName, children: containerName }, containerName))
206
+ }
207
+ ),
208
+ onSocketMessage,
209
+ onSocketClose,
210
+ onSocketStatusChange
211
+ }
212
+ );
213
+ }
214
+ );
215
+ exports.OS = OS;
216
+ exports.PodShell = PodShell;
@@ -0,0 +1,216 @@
1
+ import { S as SocketStatus, j as jsxRuntimeExports } from "./common-241b21f8.js";
2
+ import { Select, AntdOption } from "@cloudtower/eagle";
3
+ import React, { useMemo, useRef, useState, useCallback, useEffect, useImperativeHandle } from "react";
4
+ import { S as Shell } from "./index-ab97826a.js";
5
+ import { Buffer } from "buffer";
6
+ import "@xterm/addon-canvas";
7
+ import "@xterm/addon-fit";
8
+ import "@xterm/addon-search";
9
+ import "@xterm/addon-web-links";
10
+ import "@xterm/addon-webgl";
11
+ import "@xterm/xterm";
12
+ import "copy-to-clipboard";
13
+ import "lodash-es";
14
+ import "@cloudtower/icons-react";
15
+ function addParam(url, key, val) {
16
+ let out = url + (url.includes("?") ? "&" : "?");
17
+ if (!Array.isArray(val)) {
18
+ val = [val];
19
+ }
20
+ out += val.map((v) => {
21
+ if (v === null) {
22
+ return `${encodeURIComponent(key)}`;
23
+ } else {
24
+ return `${encodeURIComponent(key)}=${encodeURIComponent(v)}`;
25
+ }
26
+ }).join("&");
27
+ return out;
28
+ }
29
+ function addParams(url, params) {
30
+ if (params && typeof params === "object") {
31
+ Object.keys(params).forEach((key) => {
32
+ url = addParam(url, key, params[key]);
33
+ });
34
+ }
35
+ return url;
36
+ }
37
+ function base64Encode(str, alphabet = "normal") {
38
+ let buf;
39
+ if (str === null || typeof str === "undefined") {
40
+ return str;
41
+ }
42
+ if (typeof Buffer.from === "function" && Buffer.from !== Uint8Array.from) {
43
+ buf = Buffer.from(str);
44
+ } else {
45
+ buf = new Buffer(str);
46
+ }
47
+ if (alphabet === "url") {
48
+ const m = {
49
+ "+": "-",
50
+ "/": "_"
51
+ };
52
+ return buf.toString("base64").replace(/[+/]|=+$/g, (char) => m[char] || "");
53
+ }
54
+ return buf.toString("base64");
55
+ }
56
+ function base64DecodeToBuffer(str) {
57
+ if (str === null || typeof str === "undefined") {
58
+ return str;
59
+ }
60
+ if (typeof Buffer.from === "function" && Buffer.from !== Uint8Array.from) {
61
+ return Buffer.from(str, "base64");
62
+ } else {
63
+ return new Buffer(str, "base64");
64
+ }
65
+ }
66
+ function base64Decode(str) {
67
+ return !str ? str : base64DecodeToBuffer(str.replace(/[-_]/g, (char) => char === "-" ? "+" : "/")).toString();
68
+ }
69
+ var OS = /* @__PURE__ */ ((OS2) => {
70
+ OS2["Linux"] = "linux";
71
+ OS2["Windows"] = "windows";
72
+ return OS2;
73
+ })(OS || {});
74
+ const BACKUP_SHELLS = [
75
+ "windows",
76
+ "linux"
77
+ /* Linux */
78
+ ];
79
+ const COMMANDS = {
80
+ [
81
+ "linux"
82
+ /* Linux */
83
+ ]: [
84
+ "/bin/sh",
85
+ "-c",
86
+ 'TERM=xterm-256color; export TERM; [ -x /bin/bash ] && ([ -x /usr/bin/script ] && /usr/bin/script -q -c "/bin/bash" /dev/null || exec /bin/bash) || exec /bin/sh'
87
+ ],
88
+ [
89
+ "windows"
90
+ /* Windows */
91
+ ]: ["cmd"]
92
+ };
93
+ const PodShell = React.forwardRef(
94
+ function PodShell2(props, ref) {
95
+ const { pod, basePath, onSocketStatusChange } = props;
96
+ const id = pod.id;
97
+ const [namespace, name] = useMemo(() => id.split("/"), [id]);
98
+ const shellRef = useRef(null);
99
+ const errorMsgRef = useRef("");
100
+ const [osIndex, setOsIndex] = useState(0);
101
+ const [container, setContainer] = useState("");
102
+ const containers = useMemo(() => {
103
+ var _a, _b;
104
+ return (((_a = pod == null ? void 0 : pod._rawYaml.status) == null ? void 0 : _a.containerStatuses) || []).concat(((_b = pod == null ? void 0 : pod._rawYaml.status) == null ? void 0 : _b.initContainerStatuses) || []).map((containerStatus) => containerStatus.name);
105
+ }, [pod]);
106
+ const url = useMemo(() => {
107
+ const os = BACKUP_SHELLS[osIndex];
108
+ const protocol = location.protocol.includes("https") ? "wss" : "ws";
109
+ const url2 = container && os ? addParams(
110
+ `${protocol}://${location.host}${basePath}/api/v1/namespaces/${namespace}/pods/${name}/exec`,
111
+ {
112
+ container,
113
+ stdout: "true",
114
+ stdin: "true",
115
+ stderr: "true",
116
+ tty: "true",
117
+ command: COMMANDS[
118
+ os || "linux"
119
+ /* Linux */
120
+ ]
121
+ }
122
+ ) : "";
123
+ return url2;
124
+ }, [container, name, namespace, osIndex, basePath]);
125
+ const onSocketClose = useCallback(
126
+ (socket, term) => {
127
+ var _a, _b;
128
+ if (errorMsgRef.current) {
129
+ if (osIndex + 1 < BACKUP_SHELLS.length) {
130
+ setOsIndex(osIndex + 1);
131
+ } else {
132
+ term == null ? void 0 : term.writeln(`\x1B[38;2;255;82;82m${errorMsgRef.current}`);
133
+ (_a = shellRef.current) == null ? void 0 : _a.setSocketStatus(SocketStatus.Disconnected);
134
+ errorMsgRef.current = "";
135
+ }
136
+ } else {
137
+ (_b = shellRef.current) == null ? void 0 : _b.setSocketStatus(SocketStatus.Disconnected);
138
+ }
139
+ },
140
+ [osIndex]
141
+ );
142
+ const onSocketMessage = useCallback(
143
+ (e, socket, term) => {
144
+ const type = e.data.substr(0, 1);
145
+ const msg = base64Decode(e.data.substr(1));
146
+ if (`${type}` === "1") {
147
+ term == null ? void 0 : term.write(msg);
148
+ } else {
149
+ if (`${type}` === "3") {
150
+ errorMsgRef.current = msg;
151
+ }
152
+ }
153
+ },
154
+ []
155
+ );
156
+ const fit = useCallback(({ rows, cols }) => {
157
+ var _a;
158
+ const message = `${"4"}${base64Encode(
159
+ JSON.stringify({
160
+ Width: Math.floor(cols),
161
+ Height: Math.floor(rows)
162
+ })
163
+ )}`;
164
+ (_a = shellRef.current) == null ? void 0 : _a.send(message);
165
+ }, []);
166
+ const encode = useCallback((input) => `${"0"}${base64Encode(input)}`, []);
167
+ useEffect(() => {
168
+ if (!container && containers.length) {
169
+ setContainer(containers[0]);
170
+ }
171
+ }, [containers, container]);
172
+ useImperativeHandle(
173
+ ref,
174
+ () => ({
175
+ getAllTerminalContents: () => {
176
+ var _a;
177
+ return ((_a = shellRef.current) == null ? void 0 : _a.getAllTerminalContents()) || [];
178
+ }
179
+ }),
180
+ []
181
+ );
182
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
183
+ Shell,
184
+ {
185
+ ref: shellRef,
186
+ url,
187
+ protocols: "base64.channel.k8s.io",
188
+ encode,
189
+ fit,
190
+ toolbarLeftSlot: /* @__PURE__ */ jsxRuntimeExports.jsx(
191
+ Select,
192
+ {
193
+ input: {
194
+ value: container,
195
+ onChange(value) {
196
+ setContainer(value);
197
+ }
198
+ },
199
+ style: {
200
+ width: "256px"
201
+ },
202
+ size: "small",
203
+ children: containers.map((containerName) => /* @__PURE__ */ jsxRuntimeExports.jsx(AntdOption, { value: containerName, label: containerName, children: containerName }, containerName))
204
+ }
205
+ ),
206
+ onSocketMessage,
207
+ onSocketClose,
208
+ onSocketStatusChange
209
+ }
210
+ );
211
+ }
212
+ );
213
+ export {
214
+ OS,
215
+ PodShell
216
+ };
@@ -1,35 +1,5 @@
1
1
  "use strict";
2
2
  const React = require("react");
3
- var commonjsGlobal = typeof globalThis !== "undefined" ? globalThis : typeof window !== "undefined" ? window : typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : {};
4
- function getDefaultExportFromCjs(x) {
5
- return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
6
- }
7
- function getAugmentedNamespace(n) {
8
- if (n.__esModule)
9
- return n;
10
- var f = n.default;
11
- if (typeof f == "function") {
12
- var a = function a2() {
13
- if (this instanceof a2) {
14
- return Reflect.construct(f, arguments, this.constructor);
15
- }
16
- return f.apply(this, arguments);
17
- };
18
- a.prototype = f.prototype;
19
- } else
20
- a = {};
21
- Object.defineProperty(a, "__esModule", { value: true });
22
- Object.keys(n).forEach(function(k) {
23
- var d = Object.getOwnPropertyDescriptor(n, k);
24
- Object.defineProperty(a, k, d.get ? d : {
25
- enumerable: true,
26
- get: function() {
27
- return n[k];
28
- }
29
- });
30
- });
31
- return a;
32
- }
33
3
  function warn() {
34
4
  if (console && console.warn) {
35
5
  for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
@@ -616,9 +586,9 @@ function requireReactJsxRuntime_development() {
616
586
  }
617
587
  return config.key !== void 0;
618
588
  }
619
- function warnIfStringRefCannotBeAutoConverted(config, self2) {
589
+ function warnIfStringRefCannotBeAutoConverted(config, self) {
620
590
  {
621
- if (typeof config.ref === "string" && ReactCurrentOwner.current && self2 && ReactCurrentOwner.current.stateNode !== self2) {
591
+ if (typeof config.ref === "string" && ReactCurrentOwner.current && self && ReactCurrentOwner.current.stateNode !== self) {
622
592
  var componentName = getComponentName(ReactCurrentOwner.current.type);
623
593
  if (!didWarnAboutStringRefs[componentName]) {
624
594
  error('Component "%s" contains the string ref "%s". Support for string refs will be removed in a future major release. This case cannot be automatically converted to an arrow function. We ask you to manually fix this case by using useRef() or createRef() instead. Learn more about using refs safely here: https://reactjs.org/link/strict-mode-string-ref', getComponentName(ReactCurrentOwner.current.type), config.ref);
@@ -657,7 +627,7 @@ function requireReactJsxRuntime_development() {
657
627
  });
658
628
  }
659
629
  }
660
- var ReactElement = function(type, key, ref, self2, source, owner, props) {
630
+ var ReactElement = function(type, key, ref, self, source, owner, props) {
661
631
  var element = {
662
632
  // This tag allows us to uniquely identify this as a React Element
663
633
  $$typeof: REACT_ELEMENT_TYPE,
@@ -681,7 +651,7 @@ function requireReactJsxRuntime_development() {
681
651
  configurable: false,
682
652
  enumerable: false,
683
653
  writable: false,
684
- value: self2
654
+ value: self
685
655
  });
686
656
  Object.defineProperty(element, "_source", {
687
657
  configurable: false,
@@ -696,7 +666,7 @@ function requireReactJsxRuntime_development() {
696
666
  }
697
667
  return element;
698
668
  };
699
- function jsxDEV(type, config, maybeKey, source, self2) {
669
+ function jsxDEV(type, config, maybeKey, source, self) {
700
670
  {
701
671
  var propName;
702
672
  var props = {};
@@ -710,7 +680,7 @@ function requireReactJsxRuntime_development() {
710
680
  }
711
681
  if (hasValidRef(config)) {
712
682
  ref = config.ref;
713
- warnIfStringRefCannotBeAutoConverted(config, self2);
683
+ warnIfStringRefCannotBeAutoConverted(config, self);
714
684
  }
715
685
  for (propName in config) {
716
686
  if (hasOwnProperty.call(config, propName) && !RESERVED_PROPS.hasOwnProperty(propName)) {
@@ -734,7 +704,7 @@ function requireReactJsxRuntime_development() {
734
704
  defineRefPropWarningGetter(props, displayName);
735
705
  }
736
706
  }
737
- return ReactElement(type, key, ref, self2, source, ReactCurrentOwner.current, props);
707
+ return ReactElement(type, key, ref, self, source, ReactCurrentOwner.current, props);
738
708
  }
739
709
  }
740
710
  var ReactCurrentOwner$1 = ReactSharedInternals.ReactCurrentOwner;
@@ -885,7 +855,7 @@ function requireReactJsxRuntime_development() {
885
855
  }
886
856
  }
887
857
  }
888
- function jsxWithValidation(type, props, key, isStaticChildren, source, self2) {
858
+ function jsxWithValidation(type, props, key, isStaticChildren, source, self) {
889
859
  {
890
860
  var validType = isValidElementType(type);
891
861
  if (!validType) {
@@ -912,7 +882,7 @@ function requireReactJsxRuntime_development() {
912
882
  }
913
883
  error("React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: %s.%s", typeString, info);
914
884
  }
915
- var element = jsxDEV(type, props, key, source, self2);
885
+ var element = jsxDEV(type, props, key, source, self);
916
886
  if (element == null) {
917
887
  return element;
918
888
  }
@@ -1001,10 +971,7 @@ var SocketStatus = /* @__PURE__ */ ((SocketStatus2) => {
1001
971
  })(SocketStatus || {});
1002
972
  exports.I18nContext = I18nContext;
1003
973
  exports.SocketStatus = SocketStatus;
1004
- exports.commonjsGlobal = commonjsGlobal;
1005
974
  exports.cx_default = cx_default;
1006
- exports.getAugmentedNamespace = getAugmentedNamespace;
1007
- exports.getDefaultExportFromCjs = getDefaultExportFromCjs;
1008
975
  exports.getDefaults = getDefaults;
1009
976
  exports.getI18n = getI18n;
1010
977
  exports.jsxRuntimeExports = jsxRuntimeExports;