@orion-ds/react 5.4.0 → 5.5.1
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/components/CodeEditor/CodeEditor.cjs +6 -6
- package/dist/components/CodeEditor/CodeEditor.d.ts.map +1 -1
- package/dist/components/CodeEditor/CodeEditor.mjs +137 -138
- package/dist/contexts/ThemeContext.cjs +13 -11
- package/dist/contexts/ThemeContext.d.ts +6 -3
- package/dist/contexts/ThemeContext.d.ts.map +1 -1
- package/dist/contexts/ThemeContext.mjs +30 -26
- package/package.json +1 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const
|
|
2
|
-
`),
|
|
3
|
-
`).length,
|
|
4
|
-
`).length-1)},
|
|
5
|
-
`,
|
|
6
|
-
`})}),
|
|
1
|
+
"use strict";var Z=Object.create;var F=Object.defineProperty;var ee=Object.getOwnPropertyDescriptor;var te=Object.getOwnPropertyNames;var re=Object.getPrototypeOf,ne=Object.prototype.hasOwnProperty;var se=(r,n,d,x)=>{if(n&&typeof n=="object"||typeof n=="function")for(let h of te(n))!ne.call(r,h)&&h!==d&&F(r,h,{get:()=>n[h],enumerable:!(x=ee(n,h))||x.enumerable});return r};var O=(r,n,d)=>(d=r!=null?Z(re(r)):{},se(n||!r||!r.__esModule?F(d,"default",{value:r,enumerable:!0}):d,r));Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("react/jsx-runtime"),i=require("react"),ie=require("../MissingDependencyError.cjs"),ae=require("../../utils/optionalDeps.cjs"),o=require("./CodeEditor.module.css.cjs"),ce=require("../../contexts/ThemeContext.cjs");let k,N,S;Promise.all([import("react-syntax-highlighter"),import("react-syntax-highlighter/dist/esm/styles/prism")]).then(([r,n])=>{k=r.Prism,N=n.oneDark,S=n.oneLight}).catch(()=>{});const V=i.forwardRef(({value:r="",onChange:n,language:d,readOnly:x=!1,showLineNumbers:h=!0,placeholder:D,minRows:y=10,className:_,"aria-label":M,...H},z)=>{const[$,T]=i.useState(),[I,U]=i.useState(!0),[W,E]=i.useState(!1),[b,G]=i.useState(0),[f,J]=i.useState([]),v=i.useRef(null),j=i.useRef(null),w=i.useRef(null),q=i.useRef(null),Q=i.useRef(null),g=i.useRef(null),m=z||Q;i.useEffect(()=>{(async()=>{try{const t=ae.checkComponent("CodeEditor");t instanceof Promise?T(await t):T(t)}catch{T(void 0)}finally{U(!1)}})()},[]),i.useEffect(()=>{if(k&&N&&S){E(!0);return}const e=setTimeout(()=>{E(!0)},0);return()=>clearTimeout(e)},[]),i.useEffect(()=>{if(g.current&&m.current){const{start:e,end:t}=g.current;m.current.setSelectionRange(e,t),g.current=null}}),i.useEffect(()=>{const e=w.current,t=q.current;if(!e||!t)return;const a=()=>{const u=t.clientWidth;if(u<=0)return;e.style.width=`${u}px`;const c=r.split(`
|
|
2
|
+
`),p=Math.max(c.length,y),C=[];for(let R=0;R<p;R++){const Y=c[R]??"";e.textContent=Y||" ",C.push(e.scrollHeight)}J(C)};a();const l=new ResizeObserver(a);return l.observe(t),()=>l.disconnect()},[r,y]),i.useEffect(()=>{const e=a=>{const l=a.target;v.current&&(v.current.scrollTop=l.scrollTop),j.current&&(j.current.scrollTop=l.scrollTop,j.current.scrollLeft=l.scrollLeft)},t=m?.current;if(t)return t.addEventListener("scroll",e),()=>{t.removeEventListener("scroll",e)}},[m]);let A="dark";try{A=ce.useThemeContext().theme}catch{}const X=A==="light"?S:N,K=Math.max(r.split(`
|
|
3
|
+
`).length,y);if($)return s.jsx(ie.MissingDependencyError,{...$});if(I)return s.jsx("div",{children:"Loading code editor..."});if(d&&!W)return s.jsx("div",{children:"Loading code editor..."});const L=e=>{const t=e.value.substring(0,e.selectionStart);G(t.split(`
|
|
4
|
+
`).length-1)},P=e=>{if(e.key==="Tab"){e.preventDefault();const t=e.currentTarget,a=t.selectionStart,l=t.selectionEnd,u=" ";if(a===l){const c=r.substring(0,a)+u+r.substring(l);g.current={start:a+u.length,end:a+u.length},n?.(c)}else if(e.shiftKey){const c=r.lastIndexOf(`
|
|
5
|
+
`,a-1)+1,p=r.substring(c).match(/^ {1,2}/)?.[0]??"";if(p.length>0){const C=r.substring(0,c)+r.substring(c+p.length);g.current={start:Math.max(c,a-p.length),end:Math.max(c,l-p.length)},n?.(C)}}else{const c=r.substring(0,a)+u+r.substring(l);g.current={start:a+u.length,end:a+u.length},n?.(c)}}},B=[o.default.wrapper,_].filter(Boolean).join(" ");return d?s.jsxs("div",{className:B,style:{minHeight:`calc(${y} * 1.6em + 2 * var(--spacing-4))`},children:[s.jsx("div",{ref:w,className:o.default.lineMirror,"aria-hidden":"true"}),h&&s.jsx("div",{ref:v,className:o.default.lineNumbers,"aria-hidden":"true",children:Array.from({length:K}).map((e,t)=>s.jsx("div",{className:o.default.lineNumber,style:f[t]!==void 0?{height:`${f[t]}px`}:void 0,children:t+1},t))}),s.jsxs("div",{ref:q,className:o.default.editorArea,children:[s.jsx("div",{className:o.default.lineHighlight,style:{top:f.length>0?`calc(var(--spacing-4) + ${f.slice(0,b).reduce((e,t)=>e+t,0)}px)`:`calc(var(--spacing-4) + ${(b*1.6).toFixed(2)}em)`,...f[b]!==void 0?{height:`${f[b]}px`}:{}},"aria-hidden":"true"}),s.jsx("div",{ref:j,className:o.default.highlightLayer,"aria-hidden":"true",children:s.jsx(k,{language:d,style:X,customStyle:{margin:0,padding:0,background:"transparent",fontSize:"inherit",lineHeight:"inherit",fontFamily:"inherit",whiteSpace:"pre-wrap",wordBreak:"break-word",overflow:"visible"},codeTagProps:{style:{fontFamily:"inherit",background:"transparent",color:"var(--text-primary)",whiteSpace:"pre-wrap",wordBreak:"break-word"}},children:r+`
|
|
6
|
+
`})}),s.jsx("textarea",{ref:m,className:o.default.textareaOverlay,value:r,onChange:e=>n?.(e.target.value),onKeyDown:P,onKeyUp:e=>L(e.currentTarget),onMouseUp:e=>L(e.currentTarget),onClick:e=>L(e.currentTarget),placeholder:D,readOnly:x,"aria-label":M||"Code editor",spellCheck:"false",...H})]})]}):s.jsxs("div",{className:B,style:{minHeight:`calc(${y} * 1.6em + 2 * var(--spacing-4))`},children:[s.jsx("div",{ref:w,className:o.default.lineMirror,"aria-hidden":"true"}),h&&s.jsx("div",{ref:v,className:o.default.lineNumbers,"aria-hidden":"true",children:Array.from({length:K}).map((e,t)=>s.jsx("div",{className:o.default.lineNumber,style:f[t]!==void 0?{height:`${f[t]}px`}:void 0,children:t+1},t))}),s.jsx("textarea",{ref:m,className:o.default.textarea,value:r,onChange:e=>n?.(e.target.value),onKeyDown:P,placeholder:D,readOnly:x,"aria-label":M||"Code editor",spellCheck:"false",...H})]})});V.displayName="CodeEditor";exports.CodeEditor=V;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../src/components/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;
|
|
1
|
+
{"version":3,"file":"CodeEditor.d.ts","sourceRoot":"","sources":["../../../src/components/CodeEditor/CodeEditor.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAkD,MAAM,OAAO,CAAC;AACvE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AA+B1D;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,UAAU,6FA4XtB,CAAC"}
|
|
@@ -1,157 +1,156 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import { forwardRef as
|
|
3
|
-
import { MissingDependencyError as
|
|
4
|
-
import { checkComponent as
|
|
5
|
-
import
|
|
6
|
-
import { useThemeContext as
|
|
7
|
-
let
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
try {
|
|
17
|
-
const r = require("refractor/all");
|
|
18
|
-
r.default && r.default.registered && r.default.registered("markdown") && !r.default.languages.markdown?.["quoted-string"] && r.default.languages.insertBefore("markdown", "bold", {
|
|
19
|
-
"quoted-string": {
|
|
20
|
-
pattern: /"(?:\\.|[^"\\])*"/,
|
|
21
|
-
greedy: !0,
|
|
22
|
-
alias: "string"
|
|
23
|
-
}
|
|
24
|
-
});
|
|
25
|
-
} catch {
|
|
26
|
-
}
|
|
27
|
-
const te = X(
|
|
1
|
+
import { jsx as i, jsxs as H } from "react/jsx-runtime";
|
|
2
|
+
import { forwardRef as Z, useState as p, useRef as m, useEffect as x } from "react";
|
|
3
|
+
import { MissingDependencyError as ee } from "../MissingDependencyError.mjs";
|
|
4
|
+
import { checkComponent as te } from "../../utils/optionalDeps.mjs";
|
|
5
|
+
import o from "./CodeEditor.module.css.mjs";
|
|
6
|
+
import { useThemeContext as re } from "../../contexts/ThemeContext.mjs";
|
|
7
|
+
let N, w, C;
|
|
8
|
+
Promise.all([
|
|
9
|
+
import("react-syntax-highlighter"),
|
|
10
|
+
import("react-syntax-highlighter/dist/esm/styles/prism")
|
|
11
|
+
]).then(([r, l]) => {
|
|
12
|
+
N = r.Prism, w = l.oneDark, C = l.oneLight;
|
|
13
|
+
}).catch(() => {
|
|
14
|
+
});
|
|
15
|
+
const ne = Z(
|
|
28
16
|
({
|
|
29
17
|
value: r = "",
|
|
30
18
|
onChange: l,
|
|
31
|
-
language:
|
|
32
|
-
readOnly:
|
|
33
|
-
showLineNumbers:
|
|
34
|
-
placeholder:
|
|
35
|
-
minRows:
|
|
36
|
-
className:
|
|
37
|
-
"aria-label":
|
|
38
|
-
|
|
39
|
-
},
|
|
40
|
-
const [
|
|
41
|
-
|
|
19
|
+
language: T,
|
|
20
|
+
readOnly: $ = !1,
|
|
21
|
+
showLineNumbers: A = !0,
|
|
22
|
+
placeholder: R,
|
|
23
|
+
minRows: g = 10,
|
|
24
|
+
className: O,
|
|
25
|
+
"aria-label": K,
|
|
26
|
+
...B
|
|
27
|
+
}, U) => {
|
|
28
|
+
const [P, L] = p(), [W, _] = p(!0), [q, S] = p(!1), [y, G] = p(0), [d, J] = p([]), v = m(null), b = m(null), D = m(null), j = m(null), Q = m(null), h = m(null), u = U || Q;
|
|
29
|
+
x(() => {
|
|
42
30
|
(async () => {
|
|
43
31
|
try {
|
|
44
|
-
const t =
|
|
45
|
-
t instanceof Promise ?
|
|
32
|
+
const t = te("CodeEditor");
|
|
33
|
+
t instanceof Promise ? L(await t) : L(t);
|
|
46
34
|
} catch {
|
|
47
|
-
|
|
35
|
+
L(void 0);
|
|
48
36
|
} finally {
|
|
49
|
-
|
|
37
|
+
_(!1);
|
|
50
38
|
}
|
|
51
39
|
})();
|
|
52
|
-
}, []),
|
|
40
|
+
}, []), x(() => {
|
|
41
|
+
if (N && w && C) {
|
|
42
|
+
S(!0);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
const e = setTimeout(() => {
|
|
46
|
+
S(!0);
|
|
47
|
+
}, 0);
|
|
48
|
+
return () => clearTimeout(e);
|
|
49
|
+
}, []), x(() => {
|
|
53
50
|
if (h.current && u.current) {
|
|
54
51
|
const { start: e, end: t } = h.current;
|
|
55
52
|
u.current.setSelectionRange(e, t), h.current = null;
|
|
56
53
|
}
|
|
57
|
-
}),
|
|
58
|
-
const e =
|
|
54
|
+
}), x(() => {
|
|
55
|
+
const e = D.current, t = j.current;
|
|
59
56
|
if (!e || !t) return;
|
|
60
57
|
const n = () => {
|
|
61
|
-
const
|
|
62
|
-
if (
|
|
63
|
-
e.style.width = `${
|
|
64
|
-
const
|
|
65
|
-
`), f = Math.max(
|
|
66
|
-
for (let
|
|
67
|
-
const
|
|
68
|
-
e.textContent =
|
|
58
|
+
const a = t.clientWidth;
|
|
59
|
+
if (a <= 0) return;
|
|
60
|
+
e.style.width = `${a}px`;
|
|
61
|
+
const s = r.split(`
|
|
62
|
+
`), f = Math.max(s.length, g), k = [];
|
|
63
|
+
for (let M = 0; M < f; M++) {
|
|
64
|
+
const Y = s[M] ?? "";
|
|
65
|
+
e.textContent = Y || " ", k.push(e.scrollHeight);
|
|
69
66
|
}
|
|
70
|
-
|
|
67
|
+
J(k);
|
|
71
68
|
};
|
|
72
69
|
n();
|
|
73
|
-
const
|
|
74
|
-
return
|
|
75
|
-
}, [r,
|
|
70
|
+
const c = new ResizeObserver(n);
|
|
71
|
+
return c.observe(t), () => c.disconnect();
|
|
72
|
+
}, [r, g]), x(() => {
|
|
76
73
|
const e = (n) => {
|
|
77
|
-
const
|
|
78
|
-
|
|
74
|
+
const c = n.target;
|
|
75
|
+
v.current && (v.current.scrollTop = c.scrollTop), b.current && (b.current.scrollTop = c.scrollTop, b.current.scrollLeft = c.scrollLeft);
|
|
79
76
|
}, t = u?.current;
|
|
80
77
|
if (t)
|
|
81
78
|
return t.addEventListener("scroll", e), () => {
|
|
82
79
|
t.removeEventListener("scroll", e);
|
|
83
80
|
};
|
|
84
81
|
}, [u]);
|
|
85
|
-
let
|
|
82
|
+
let F = "dark";
|
|
86
83
|
try {
|
|
87
|
-
|
|
84
|
+
F = re().theme;
|
|
88
85
|
} catch {
|
|
89
86
|
}
|
|
90
|
-
const
|
|
91
|
-
`).length,
|
|
92
|
-
if (
|
|
93
|
-
return /* @__PURE__ */
|
|
94
|
-
if (
|
|
95
|
-
return /* @__PURE__ */
|
|
96
|
-
|
|
87
|
+
const X = F === "light" ? C : w, V = Math.max(r.split(`
|
|
88
|
+
`).length, g);
|
|
89
|
+
if (P)
|
|
90
|
+
return /* @__PURE__ */ i(ee, { ...P });
|
|
91
|
+
if (W)
|
|
92
|
+
return /* @__PURE__ */ i("div", { children: "Loading code editor..." });
|
|
93
|
+
if (T && !q)
|
|
94
|
+
return /* @__PURE__ */ i("div", { children: "Loading code editor..." });
|
|
95
|
+
const E = (e) => {
|
|
97
96
|
const t = e.value.substring(0, e.selectionStart);
|
|
98
|
-
|
|
97
|
+
G(t.split(`
|
|
99
98
|
`).length - 1);
|
|
100
|
-
},
|
|
99
|
+
}, z = (e) => {
|
|
101
100
|
if (e.key === "Tab") {
|
|
102
101
|
e.preventDefault();
|
|
103
|
-
const t = e.currentTarget, n = t.selectionStart,
|
|
104
|
-
if (n ===
|
|
105
|
-
const
|
|
102
|
+
const t = e.currentTarget, n = t.selectionStart, c = t.selectionEnd, a = " ";
|
|
103
|
+
if (n === c) {
|
|
104
|
+
const s = r.substring(0, n) + a + r.substring(c);
|
|
106
105
|
h.current = {
|
|
107
|
-
start: n +
|
|
108
|
-
end: n +
|
|
109
|
-
}, l?.(
|
|
106
|
+
start: n + a.length,
|
|
107
|
+
end: n + a.length
|
|
108
|
+
}, l?.(s);
|
|
110
109
|
} else if (e.shiftKey) {
|
|
111
|
-
const
|
|
112
|
-
`, n - 1) + 1, f = r.substring(
|
|
110
|
+
const s = r.lastIndexOf(`
|
|
111
|
+
`, n - 1) + 1, f = r.substring(s).match(/^ {1,2}/)?.[0] ?? "";
|
|
113
112
|
if (f.length > 0) {
|
|
114
|
-
const
|
|
113
|
+
const k = r.substring(0, s) + r.substring(s + f.length);
|
|
115
114
|
h.current = {
|
|
116
|
-
start: Math.max(
|
|
117
|
-
end: Math.max(
|
|
118
|
-
}, l?.(
|
|
115
|
+
start: Math.max(s, n - f.length),
|
|
116
|
+
end: Math.max(s, c - f.length)
|
|
117
|
+
}, l?.(k);
|
|
119
118
|
}
|
|
120
119
|
} else {
|
|
121
|
-
const
|
|
120
|
+
const s = r.substring(0, n) + a + r.substring(c);
|
|
122
121
|
h.current = {
|
|
123
|
-
start: n +
|
|
124
|
-
end: n +
|
|
125
|
-
}, l?.(
|
|
122
|
+
start: n + a.length,
|
|
123
|
+
end: n + a.length
|
|
124
|
+
}, l?.(s);
|
|
126
125
|
}
|
|
127
126
|
}
|
|
128
|
-
},
|
|
129
|
-
return
|
|
127
|
+
}, I = [o.wrapper, O].filter(Boolean).join(" ");
|
|
128
|
+
return T ? /* @__PURE__ */ H(
|
|
130
129
|
"div",
|
|
131
130
|
{
|
|
132
|
-
className:
|
|
131
|
+
className: I,
|
|
133
132
|
style: {
|
|
134
|
-
minHeight: `calc(${
|
|
133
|
+
minHeight: `calc(${g} * 1.6em + 2 * var(--spacing-4))`
|
|
135
134
|
},
|
|
136
135
|
children: [
|
|
137
|
-
/* @__PURE__ */
|
|
136
|
+
/* @__PURE__ */ i(
|
|
138
137
|
"div",
|
|
139
138
|
{
|
|
140
|
-
ref:
|
|
141
|
-
className:
|
|
139
|
+
ref: D,
|
|
140
|
+
className: o.lineMirror,
|
|
142
141
|
"aria-hidden": "true"
|
|
143
142
|
}
|
|
144
143
|
),
|
|
145
|
-
|
|
144
|
+
A && /* @__PURE__ */ i(
|
|
146
145
|
"div",
|
|
147
146
|
{
|
|
148
|
-
ref:
|
|
149
|
-
className:
|
|
147
|
+
ref: v,
|
|
148
|
+
className: o.lineNumbers,
|
|
150
149
|
"aria-hidden": "true",
|
|
151
|
-
children: Array.from({ length:
|
|
150
|
+
children: Array.from({ length: V }).map((e, t) => /* @__PURE__ */ i(
|
|
152
151
|
"div",
|
|
153
152
|
{
|
|
154
|
-
className:
|
|
153
|
+
className: o.lineNumber,
|
|
155
154
|
style: d[t] !== void 0 ? { height: `${d[t]}px` } : void 0,
|
|
156
155
|
children: t + 1
|
|
157
156
|
},
|
|
@@ -159,29 +158,29 @@ const te = X(
|
|
|
159
158
|
))
|
|
160
159
|
}
|
|
161
160
|
),
|
|
162
|
-
/* @__PURE__ */
|
|
163
|
-
/* @__PURE__ */
|
|
161
|
+
/* @__PURE__ */ H("div", { ref: j, className: o.editorArea, children: [
|
|
162
|
+
/* @__PURE__ */ i(
|
|
164
163
|
"div",
|
|
165
164
|
{
|
|
166
|
-
className:
|
|
165
|
+
className: o.lineHighlight,
|
|
167
166
|
style: {
|
|
168
|
-
top: d.length > 0 ? `calc(var(--spacing-4) + ${d.slice(0,
|
|
169
|
-
...d[
|
|
167
|
+
top: d.length > 0 ? `calc(var(--spacing-4) + ${d.slice(0, y).reduce((e, t) => e + t, 0)}px)` : `calc(var(--spacing-4) + ${(y * 1.6).toFixed(2)}em)`,
|
|
168
|
+
...d[y] !== void 0 ? { height: `${d[y]}px` } : {}
|
|
170
169
|
},
|
|
171
170
|
"aria-hidden": "true"
|
|
172
171
|
}
|
|
173
172
|
),
|
|
174
|
-
/* @__PURE__ */
|
|
173
|
+
/* @__PURE__ */ i(
|
|
175
174
|
"div",
|
|
176
175
|
{
|
|
177
|
-
ref:
|
|
178
|
-
className:
|
|
176
|
+
ref: b,
|
|
177
|
+
className: o.highlightLayer,
|
|
179
178
|
"aria-hidden": "true",
|
|
180
|
-
children: /* @__PURE__ */
|
|
181
|
-
|
|
179
|
+
children: /* @__PURE__ */ i(
|
|
180
|
+
N,
|
|
182
181
|
{
|
|
183
|
-
language:
|
|
184
|
-
style:
|
|
182
|
+
language: T,
|
|
183
|
+
style: X,
|
|
185
184
|
customStyle: {
|
|
186
185
|
margin: 0,
|
|
187
186
|
padding: 0,
|
|
@@ -208,44 +207,44 @@ const te = X(
|
|
|
208
207
|
)
|
|
209
208
|
}
|
|
210
209
|
),
|
|
211
|
-
/* @__PURE__ */
|
|
210
|
+
/* @__PURE__ */ i(
|
|
212
211
|
"textarea",
|
|
213
212
|
{
|
|
214
213
|
ref: u,
|
|
215
|
-
className:
|
|
214
|
+
className: o.textareaOverlay,
|
|
216
215
|
value: r,
|
|
217
216
|
onChange: (e) => l?.(e.target.value),
|
|
218
|
-
onKeyDown:
|
|
219
|
-
onKeyUp: (e) =>
|
|
220
|
-
onMouseUp: (e) =>
|
|
221
|
-
onClick: (e) =>
|
|
222
|
-
placeholder:
|
|
223
|
-
readOnly:
|
|
224
|
-
"aria-label":
|
|
217
|
+
onKeyDown: z,
|
|
218
|
+
onKeyUp: (e) => E(e.currentTarget),
|
|
219
|
+
onMouseUp: (e) => E(e.currentTarget),
|
|
220
|
+
onClick: (e) => E(e.currentTarget),
|
|
221
|
+
placeholder: R,
|
|
222
|
+
readOnly: $,
|
|
223
|
+
"aria-label": K || "Code editor",
|
|
225
224
|
spellCheck: "false",
|
|
226
|
-
|
|
225
|
+
...B
|
|
227
226
|
}
|
|
228
227
|
)
|
|
229
228
|
] })
|
|
230
229
|
]
|
|
231
230
|
}
|
|
232
|
-
) : /* @__PURE__ */
|
|
231
|
+
) : /* @__PURE__ */ H(
|
|
233
232
|
"div",
|
|
234
233
|
{
|
|
235
|
-
className:
|
|
236
|
-
style: { minHeight: `calc(${
|
|
234
|
+
className: I,
|
|
235
|
+
style: { minHeight: `calc(${g} * 1.6em + 2 * var(--spacing-4))` },
|
|
237
236
|
children: [
|
|
238
|
-
/* @__PURE__ */
|
|
239
|
-
|
|
237
|
+
/* @__PURE__ */ i("div", { ref: D, className: o.lineMirror, "aria-hidden": "true" }),
|
|
238
|
+
A && /* @__PURE__ */ i(
|
|
240
239
|
"div",
|
|
241
240
|
{
|
|
242
|
-
ref:
|
|
243
|
-
className:
|
|
241
|
+
ref: v,
|
|
242
|
+
className: o.lineNumbers,
|
|
244
243
|
"aria-hidden": "true",
|
|
245
|
-
children: Array.from({ length:
|
|
244
|
+
children: Array.from({ length: V }).map((e, t) => /* @__PURE__ */ i(
|
|
246
245
|
"div",
|
|
247
246
|
{
|
|
248
|
-
className:
|
|
247
|
+
className: o.lineNumber,
|
|
249
248
|
style: d[t] !== void 0 ? { height: `${d[t]}px` } : void 0,
|
|
250
249
|
children: t + 1
|
|
251
250
|
},
|
|
@@ -253,19 +252,19 @@ const te = X(
|
|
|
253
252
|
))
|
|
254
253
|
}
|
|
255
254
|
),
|
|
256
|
-
/* @__PURE__ */
|
|
255
|
+
/* @__PURE__ */ i(
|
|
257
256
|
"textarea",
|
|
258
257
|
{
|
|
259
258
|
ref: u,
|
|
260
|
-
className:
|
|
259
|
+
className: o.textarea,
|
|
261
260
|
value: r,
|
|
262
261
|
onChange: (e) => l?.(e.target.value),
|
|
263
|
-
onKeyDown:
|
|
264
|
-
placeholder:
|
|
265
|
-
readOnly:
|
|
266
|
-
"aria-label":
|
|
262
|
+
onKeyDown: z,
|
|
263
|
+
placeholder: R,
|
|
264
|
+
readOnly: $,
|
|
265
|
+
"aria-label": K || "Code editor",
|
|
267
266
|
spellCheck: "false",
|
|
268
|
-
|
|
267
|
+
...B
|
|
269
268
|
}
|
|
270
269
|
)
|
|
271
270
|
]
|
|
@@ -273,7 +272,7 @@ const te = X(
|
|
|
273
272
|
);
|
|
274
273
|
}
|
|
275
274
|
);
|
|
276
|
-
|
|
275
|
+
ne.displayName = "CodeEditor";
|
|
277
276
|
export {
|
|
278
|
-
|
|
277
|
+
ne as CodeEditor
|
|
279
278
|
};
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),t=require("react"),S=require("../hooks/useTheme.cjs"),i=require("../utils/fonts.cjs"),O=require("../components/FontLoader/FontLoader.cjs"),h={theme:"light",brand:"orion",setTheme:()=>{},setBrand:()=>{},toggleTheme:()=>{},isDark:!1,isLight:!0},p=t.createContext(h);function P(){return typeof window>"u"?!0:getComputedStyle(document.documentElement).getPropertyValue("--orion-react-styles-loaded").trim()==="1"}function x({children:o,defaultTheme:r,defaultBrand:d,options:T,disableFontWarnings:c=!1,disableAutoFontLoading:
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const f=require("react/jsx-runtime"),t=require("react"),S=require("../hooks/useTheme.cjs"),i=require("../utils/fonts.cjs"),O=require("../components/FontLoader/FontLoader.cjs"),h={theme:"light",brand:"orion",setTheme:()=>{},setBrand:()=>{},toggleTheme:()=>{},isDark:!1,isLight:!0},p=t.createContext(h);function P(){return typeof window>"u"?!0:getComputedStyle(document.documentElement).getPropertyValue("--orion-react-styles-loaded").trim()==="1"}function x({children:o,defaultTheme:r,defaultBrand:d,options:T,disableFontWarnings:c=!1,disableAutoFontLoading:v=!1,disableCSSWarnings:u=!1}){const g={...T,...r!==void 0&&{defaultTheme:r},...d!==void 0&&{defaultBrand:d}},n=S.useTheme(g),a=t.useRef(new Set),m=t.useRef(!1);return t.useEffect(()=>{if(u||typeof window>"u"||!(process.env.NODE_ENV==="development"||window.location.hostname==="localhost"))return;const s=setTimeout(()=>{!m.current&&!P()&&(m.current=!0,console.warn(`[Orion] Component styles not detected!
|
|
2
2
|
|
|
3
3
|
You must import the component CSS file:
|
|
4
4
|
|
|
@@ -6,7 +6,7 @@ You must import the component CSS file:
|
|
|
6
6
|
|
|
7
7
|
Add this import in your app entry file. It includes both design tokens and component styles.
|
|
8
8
|
|
|
9
|
-
To disable this warning, set disableCSSWarnings={true} on ThemeProvider.`))},100);return()=>clearTimeout(s)},[u]),t.useEffect(()=>{if(c||typeof window>"u"||!(process.env.NODE_ENV==="development"||typeof window<"u"&&window.location.hostname==="localhost"))return;const s=setTimeout(()=>{const{brand:e}=n,
|
|
9
|
+
To disable this warning, set disableCSSWarnings={true} on ThemeProvider.`))},100);return()=>clearTimeout(s)},[u]),t.useEffect(()=>{if(c||typeof window>"u"||!(process.env.NODE_ENV==="development"||typeof window<"u"&&window.location.hostname==="localhost"))return;const s=setTimeout(()=>{const{brand:e}=n,l=i.getMissingFonts(e);if(l.length>0&&!a.current.has(e)){a.current.add(e);const w=i.BRAND_FONTS[e].join(", ");console.warn(`[Orion] Missing fonts for "${e}" brand: ${l.join(", ")}
|
|
10
10
|
|
|
11
11
|
The "${e}" brand requires these fonts: ${w}
|
|
12
12
|
|
|
@@ -24,14 +24,16 @@ Option 2: Add Google Fonts to your HTML <head>
|
|
|
24
24
|
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
|
25
25
|
<link href="${i.GOOGLE_FONTS_URL}" rel="stylesheet">
|
|
26
26
|
|
|
27
|
-
To disable this warning, set disableFontWarnings={true} on ThemeProvider.`)}},1e3);return()=>clearTimeout(s)},[n.brand,c,n]),f.jsxs(p.Provider,{value:n,children:[!
|
|
27
|
+
To disable this warning, set disableFontWarnings={true} on ThemeProvider.`)}},1e3);return()=>clearTimeout(s)},[n.brand,c,n]),f.jsxs(p.Provider,{value:n,children:[!v&&f.jsx(O.FontLoader,{}),o]})}function C(){const o=t.useContext(p);if(o===h&&process.env.NODE_ENV==="development")throw new Error(`useThemeContext must be used within a <ThemeProvider> component.
|
|
28
28
|
|
|
29
|
-
|
|
29
|
+
Wrap your app at the root:
|
|
30
30
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
import { ThemeProvider } from '@orion-ds/react';
|
|
32
|
+
|
|
33
|
+
export default function App() {
|
|
34
|
+
return (
|
|
35
|
+
<ThemeProvider>
|
|
36
|
+
<YourComponents />
|
|
37
|
+
</ThemeProvider>
|
|
38
|
+
);
|
|
39
|
+
}`);return o}exports.ThemeProvider=x;exports.useThemeContext=C;
|
|
@@ -55,13 +55,16 @@ export declare function ThemeProvider({ children, defaultTheme, defaultBrand, op
|
|
|
55
55
|
*
|
|
56
56
|
* ⚠️ IMPORTANT: Must be used inside a ThemeProvider for full functionality
|
|
57
57
|
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
58
|
+
* **Development**: Throws a clear error if used outside ThemeProvider
|
|
59
|
+
* (helps catch integration mistakes early)
|
|
60
|
+
*
|
|
61
|
+
* **Production**: Returns SSR-safe defaults if used outside ThemeProvider
|
|
62
|
+
* (maintains compatibility during Next.js static prerendering)
|
|
60
63
|
*
|
|
61
64
|
* @example
|
|
62
65
|
* ```tsx
|
|
63
66
|
* function MyComponent() {
|
|
64
|
-
* const { theme, brand, setTheme, setBrand } =
|
|
67
|
+
* const { theme, brand, setTheme, setBrand } = useThemeContext();
|
|
65
68
|
* // Components automatically inherit theme/brand from <html> attributes
|
|
66
69
|
* // DO NOT pass brand prop to components - it's applied globally!
|
|
67
70
|
* }
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/contexts/ThemeContext.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAoC3B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;IAEjE;;;OAGG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,mBAA2B,EAC3B,sBAA8B,EAC9B,kBAA0B,GAC3B,EAAE,kBAAkB,2CA2FpB;AAED
|
|
1
|
+
{"version":3,"file":"ThemeContext.d.ts","sourceRoot":"","sources":["../../src/contexts/ThemeContext.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH,OAAO,EAKL,KAAK,SAAS,EACf,MAAM,OAAO,CAAC;AACf,OAAO,EAEL,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,mBAAmB,CAAC;AAoC3B;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC;;OAEG;IACH,QAAQ,EAAE,SAAS,CAAC;IAEpB;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IAEhC;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,KAAK,GAAG,UAAU,GAAG,QAAQ,GAAG,OAAO,CAAC;IAEjE;;;OAGG;IACH,OAAO,CAAC,EAAE,eAAe,CAAC;IAE1B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAE9B;;;;;OAKG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;CAC9B;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,EAC5B,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,OAAO,EACP,mBAA2B,EAC3B,sBAA8B,EAC9B,kBAA0B,GAC3B,EAAE,kBAAkB,2CA2FpB;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,eAAe,IAAI,cAAc,CAyBhD"}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsxs as y, jsx as S } from "react/jsx-runtime";
|
|
2
|
-
import { useRef as
|
|
2
|
+
import { useRef as u, useEffect as l, useContext as O, createContext as x } from "react";
|
|
3
3
|
import { useTheme as C } from "../hooks/useTheme.mjs";
|
|
4
|
-
import { getMissingFonts as
|
|
5
|
-
import { FontLoader as
|
|
4
|
+
import { getMissingFonts as E, BRAND_FONTS as P, GOOGLE_FONTS_URL as D } from "../utils/fonts.mjs";
|
|
5
|
+
import { FontLoader as F } from "../components/FontLoader/FontLoader.mjs";
|
|
6
6
|
const f = {
|
|
7
7
|
theme: "light",
|
|
8
8
|
brand: "orion",
|
|
@@ -18,7 +18,7 @@ const f = {
|
|
|
18
18
|
function L() {
|
|
19
19
|
return typeof window > "u" ? !0 : getComputedStyle(document.documentElement).getPropertyValue("--orion-react-styles-loaded").trim() === "1";
|
|
20
20
|
}
|
|
21
|
-
function
|
|
21
|
+
function R({
|
|
22
22
|
children: o,
|
|
23
23
|
defaultTheme: n,
|
|
24
24
|
defaultBrand: s,
|
|
@@ -27,15 +27,15 @@ function A({
|
|
|
27
27
|
disableAutoFontLoading: T = !1,
|
|
28
28
|
disableCSSWarnings: d = !1
|
|
29
29
|
}) {
|
|
30
|
-
const
|
|
30
|
+
const v = {
|
|
31
31
|
...h,
|
|
32
32
|
...n !== void 0 && { defaultTheme: n },
|
|
33
33
|
...s !== void 0 && { defaultBrand: s }
|
|
34
|
-
}, t = C(
|
|
35
|
-
return
|
|
34
|
+
}, t = C(v), m = u(/* @__PURE__ */ new Set()), c = u(!1);
|
|
35
|
+
return l(() => {
|
|
36
36
|
if (d || typeof window > "u" || !(process.env.NODE_ENV === "development" || window.location.hostname === "localhost")) return;
|
|
37
37
|
const r = setTimeout(() => {
|
|
38
|
-
!
|
|
38
|
+
!c.current && !L() && (c.current = !0, console.warn(
|
|
39
39
|
`[Orion] Component styles not detected!
|
|
40
40
|
|
|
41
41
|
You must import the component CSS file:
|
|
@@ -48,15 +48,15 @@ To disable this warning, set disableCSSWarnings={true} on ThemeProvider.`
|
|
|
48
48
|
));
|
|
49
49
|
}, 100);
|
|
50
50
|
return () => clearTimeout(r);
|
|
51
|
-
}, [d]),
|
|
51
|
+
}, [d]), l(() => {
|
|
52
52
|
if (i || typeof window > "u" || !(process.env.NODE_ENV === "development" || typeof window < "u" && window.location.hostname === "localhost")) return;
|
|
53
53
|
const r = setTimeout(() => {
|
|
54
|
-
const { brand: e } = t,
|
|
55
|
-
if (
|
|
56
|
-
|
|
54
|
+
const { brand: e } = t, a = E(e);
|
|
55
|
+
if (a.length > 0 && !m.current.has(e)) {
|
|
56
|
+
m.current.add(e);
|
|
57
57
|
const w = P[e].join(", ");
|
|
58
58
|
console.warn(
|
|
59
|
-
`[Orion] Missing fonts for "${e}" brand: ${
|
|
59
|
+
`[Orion] Missing fonts for "${e}" brand: ${a.join(", ")}
|
|
60
60
|
|
|
61
61
|
The "${e}" brand requires these fonts: ${w}
|
|
62
62
|
|
|
@@ -80,27 +80,31 @@ To disable this warning, set disableFontWarnings={true} on ThemeProvider.`
|
|
|
80
80
|
}, 1e3);
|
|
81
81
|
return () => clearTimeout(r);
|
|
82
82
|
}, [t.brand, i, t]), /* @__PURE__ */ y(p.Provider, { value: t, children: [
|
|
83
|
-
!T && /* @__PURE__ */ S(
|
|
83
|
+
!T && /* @__PURE__ */ S(F, {}),
|
|
84
84
|
o
|
|
85
85
|
] });
|
|
86
86
|
}
|
|
87
87
|
function $() {
|
|
88
88
|
const o = O(p);
|
|
89
|
-
|
|
90
|
-
|
|
89
|
+
if (o === f && process.env.NODE_ENV === "development")
|
|
90
|
+
throw new Error(
|
|
91
|
+
`useThemeContext must be used within a <ThemeProvider> component.
|
|
91
92
|
|
|
92
|
-
|
|
93
|
+
Wrap your app at the root:
|
|
93
94
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
95
|
+
import { ThemeProvider } from '@orion-ds/react';
|
|
96
|
+
|
|
97
|
+
export default function App() {
|
|
98
|
+
return (
|
|
99
|
+
<ThemeProvider>
|
|
100
|
+
<YourComponents />
|
|
101
|
+
</ThemeProvider>
|
|
102
|
+
);
|
|
103
|
+
}`
|
|
104
|
+
);
|
|
105
|
+
return o;
|
|
102
106
|
}
|
|
103
107
|
export {
|
|
104
|
-
|
|
108
|
+
R as ThemeProvider,
|
|
105
109
|
$ as useThemeContext
|
|
106
110
|
};
|
package/package.json
CHANGED