@tooark/code 1.6.0 → 1.7.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.
package/dist/index.js CHANGED
@@ -19,8 +19,9 @@ function resolveCodeTheme(theme, element) {
19
19
  return resolveColorScheme(element);
20
20
  }
21
21
  // --- Tema ---
22
- // Cores de sintaxe por lado; o chrome (fundo, texto, bordas, seleção) vem dos tokens --ark-color-* com fallback,
23
- // para o editor seguir o tema do app mesmo sem o CSS do @tooark/web-components na página.
22
+ // Cores de sintaxe por lado, fallback dos tokens --ark-syntax-* (os mesmos valores, em light-dark() no tokens.css); o
23
+ // chrome (fundo, texto, bordas, seleção) vem dos tokens --ark-color-* com fallback, para o editor seguir o tema do app
24
+ // mesmo sem o CSS do @tooark/web-components na página.
24
25
  const SYNTAX = {
25
26
  light: {
26
27
  keyword: "#6d28d9",
@@ -102,12 +103,16 @@ function chromeTheme(side) {
102
103
  border: `1px solid ${v("border", f.border)}`,
103
104
  borderRadius: "0.5rem",
104
105
  fontSize: "var(--ark-code-font-size, 0.875rem)",
105
- minHeight: "var(--ark-code-min-height, 8rem)"
106
+ minHeight: "var(--ark-code-min-height, 8rem)",
107
+ // Sem `max-height` a variável não existe e o editor cresce com o conteúdo; com ela o scroller do CodeMirror
108
+ // (overflow-x auto, logo também y) rola por dentro.
109
+ maxHeight: "var(--ark-code-max-height, none)"
106
110
  },
107
111
  // Uma linha na altura do controle: a borda (2px) e a linha (1.5em) saem da altura, o resto vira respiro
108
112
  // vertical do conteúdo, que ocupa a caixa toda (o clique em qualquer ponto posiciona o cursor).
109
113
  "&.cm-ark-single-line": {
110
- minHeight: "var(--ark-code-control-height, 2.25rem)"
114
+ minHeight: "var(--ark-code-control-height, 2.25rem)",
115
+ maxHeight: "none"
111
116
  },
112
117
  "&.cm-ark-single-line .cm-scroller": {
113
118
  minHeight: "0",
@@ -256,7 +261,9 @@ function chromeTheme(side) {
256
261
  }, { dark: side === "dark" });
257
262
  }
258
263
  function syntaxTheme(side) {
259
- const c = SYNTAX[side];
264
+ // Cada papel lê o token do app; sem ele, a cor embutida do lado. O light-dark() do token resolve pelo color-scheme
265
+ // que o editor declara, então um tema fixo (`theme="dark"` numa página clara) pega o lado certo.
266
+ const c = Object.fromEntries(Object.entries(SYNTAX[side]).map(([role, color]) => [role, `var(--ark-syntax-${role}, ${color})`]));
260
267
  return syntaxHighlighting(HighlightStyle.define([
261
268
  { tag: [tags.keyword, tags.modifier, tags.operatorKeyword, tags.controlKeyword], color: c.keyword },
262
269
  { tag: [tags.string, tags.special(tags.string)], color: c.string },
@@ -654,6 +661,15 @@ function createCodeEditor(parent, options = {}) {
654
661
  });
655
662
  const view = new EditorView({ state, parent });
656
663
  view.dom.style.setProperty("--ark-code-min-height", options.minHeight ?? "8rem");
664
+ const applyMaxHeight = (value) => {
665
+ if (value?.trim()) {
666
+ view.dom.style.setProperty("--ark-code-max-height", value.trim());
667
+ }
668
+ else {
669
+ view.dom.style.removeProperty("--ark-code-max-height");
670
+ }
671
+ };
672
+ applyMaxHeight(options.maxHeight);
657
673
  applySize(normalizeSize(options.size));
658
674
  return {
659
675
  view,
@@ -698,6 +714,7 @@ function createCodeEditor(parent, options = {}) {
698
714
  },
699
715
  setWrap: (on) => view.dispatch({ effects: wrapping.reconfigure(on ? EditorView.lineWrapping : []) }),
700
716
  setMinHeight: (value) => view.dom.style.setProperty("--ark-code-min-height", value),
717
+ setMaxHeight: applyMaxHeight,
701
718
  setIndent: (style, size) => {
702
719
  indentStyle = style;
703
720
  indentSize = size;
@@ -830,7 +847,8 @@ const NO_EXTENSIONS = [];
830
847
  * O texto vai pela propriedade `value` (ou pelo atributo `value` como valor
831
848
  * inicial) e volta em `change` com `detail: { value }` a cada edição do
832
849
  * usuário. Atributos: `language` (json | javascript | yaml | text),
833
- * `readonly`, `placeholder`, `min-height` (comprimento CSS), `line-numbers`,
850
+ * `readonly`, `placeholder`, `min-height` e `max-height` (comprimentos CSS;
851
+ * acima da máxima o conteúdo rola por dentro), `line-numbers`,
834
852
  * `fold`, `tab-indent` e `autocomplete` (ligados por padrão; "false"
835
853
  * desliga), `wrap`, `indent-style` (space | tab), `indent-size`,
836
854
  * `line-ending` (lf | crlf | auto), `theme` (auto | light | dark),
@@ -872,6 +890,7 @@ class ArkCodeEditor extends HTMLElementBase {
872
890
  "readonly",
873
891
  "placeholder",
874
892
  "min-height",
893
+ "max-height",
875
894
  "line-numbers",
876
895
  "fold",
877
896
  "wrap",
@@ -1074,6 +1093,21 @@ class ArkCodeEditor extends HTMLElementBase {
1074
1093
  this.removeAttribute("min-height");
1075
1094
  }
1076
1095
  }
1096
+ /**
1097
+ * Altura máxima do editor (atributo `max-height`, comprimento CSS): acima dela o conteúdo rola dentro do editor.
1098
+ * Ignorada em `single-line`. Padrão: "" (sem limite, cresce com o conteúdo).
1099
+ */
1100
+ get maxHeight() {
1101
+ return this.getAttribute("max-height")?.trim() || "";
1102
+ }
1103
+ set maxHeight(value) {
1104
+ if (value) {
1105
+ this.setAttribute("max-height", value);
1106
+ }
1107
+ else {
1108
+ this.removeAttribute("max-height");
1109
+ }
1110
+ }
1077
1111
  get theme() {
1078
1112
  const value = (this.getAttribute("theme") || "auto").toLowerCase();
1079
1113
  return value === "light" || value === "dark" ? value : "auto";
@@ -1113,6 +1147,8 @@ class ArkCodeEditor extends HTMLElementBase {
1113
1147
  this.instance.setLabel(newValue || undefined);
1114
1148
  if (name === "min-height")
1115
1149
  this.instance.setMinHeight(this.minHeight);
1150
+ if (name === "max-height")
1151
+ this.instance.setMaxHeight(this.maxHeight);
1116
1152
  if (name === "line-numbers")
1117
1153
  this.instance.setLineNumbers(this.lineNumbers);
1118
1154
  if (name === "fold")
@@ -1166,6 +1202,7 @@ class ArkCodeEditor extends HTMLElementBase {
1166
1202
  fold: this.fold,
1167
1203
  wrap: this.wrap,
1168
1204
  minHeight: this.minHeight,
1205
+ maxHeight: this.maxHeight || undefined,
1169
1206
  indentStyle: this.indentStyle,
1170
1207
  indentSize: this.indentSize,
1171
1208
  lineEnding: this.lineEnding,