@sofereditor/react 0.4.0 → 0.5.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.cjs CHANGED
@@ -2248,7 +2248,8 @@ function TableView({ block, index, tableFragment }) {
2248
2248
  (0, import_core4.cellBorderStyle)(
2249
2249
  block.attrs.borderPreset,
2250
2250
  { row: r, col: c, rowspan, colspan, cols, rowStart, rowEnd },
2251
- "screen"
2251
+ "screen",
2252
+ block.attrs.borderColor
2252
2253
  )
2253
2254
  ),
2254
2255
  className: inRect ? "ed-cell ed-cell--selected" : "ed-cell",
@@ -3043,6 +3044,16 @@ function useEditor(opts = {}) {
3043
3044
  if (!doc.isTable(sel.focus.blockIndex)) return "all";
3044
3045
  return doc.getBlockAttrs(sel.focus.blockIndex).borderPreset ?? "all";
3045
3046
  }, [doc]);
3047
+ const setTableBorderColor = (0, import_react13.useCallback)((color) => {
3048
+ const sel = selectionRef.current;
3049
+ if (!doc.isTable(sel.focus.blockIndex)) return;
3050
+ (0, import_core5.setBlockAttrAtIndex)(ctxRef.current, sel.focus.blockIndex, "borderColor", color);
3051
+ }, [doc]);
3052
+ const getTableBorderColor = (0, import_react13.useCallback)(() => {
3053
+ const sel = selectionRef.current;
3054
+ if (!doc.isTable(sel.focus.blockIndex)) return void 0;
3055
+ return doc.getBlockAttrs(sel.focus.blockIndex).borderColor;
3056
+ }, [doc]);
3046
3057
  const isListActive = (0, import_react13.useCallback)(
3047
3058
  (kind) => {
3048
3059
  const sel = selectionRef.current;
@@ -3289,6 +3300,8 @@ function useEditor(opts = {}) {
3289
3300
  getCellBackground,
3290
3301
  setTableBorderPreset,
3291
3302
  getTableBorderPreset,
3303
+ setTableBorderColor,
3304
+ getTableBorderColor,
3292
3305
  isListActive,
3293
3306
  toggleList,
3294
3307
  indentList,
@@ -4276,6 +4289,15 @@ var ALIGN_OPTIONS = [
4276
4289
  { value: "justify", label: "\u2630", title: "Justificar" }
4277
4290
  ];
4278
4291
  var IMAGE_ALIGN_VALUES = /* @__PURE__ */ new Set(["left", "center", "right"]);
4292
+ var NATIVE_CONTROL_TAGS = /* @__PURE__ */ new Set(["SELECT", "INPUT", "OPTION"]);
4293
+ function isNativeControl(t) {
4294
+ const el = t;
4295
+ return !!el && NATIVE_CONTROL_TAGS.has(el.tagName);
4296
+ }
4297
+ function keepsOwnMouseDown(t) {
4298
+ const el = t;
4299
+ return !!el && (NATIVE_CONTROL_TAGS.has(el.tagName) || el.tagName === "BUTTON");
4300
+ }
4279
4301
  var IMAGE_LAYOUT_OPTIONS = [
4280
4302
  { value: "inline", label: "\u2194", title: "Inline (no fluxo do texto)" },
4281
4303
  { value: "wrap-left", label: "\u25E7", title: "Texto contorna \xE0 direita" },
@@ -4308,10 +4330,7 @@ function Toolbar({ className }) {
4308
4330
  const blockAlign = getAlign();
4309
4331
  const blockDir = getBlockAttr("dir");
4310
4332
  const stop = (e) => {
4311
- const t = e.target;
4312
- if (t && (t.tagName === "SELECT" || t.tagName === "INPUT" || t.tagName === "OPTION")) {
4313
- return;
4314
- }
4333
+ if (isNativeControl(e.target)) return;
4315
4334
  e.preventDefault();
4316
4335
  };
4317
4336
  const onToggle = (name) => (e) => {
@@ -4743,10 +4762,7 @@ function AnswerLinesMenu() {
4743
4762
  className: "ed-table-popover ed-answerlines-popover",
4744
4763
  role: "menu",
4745
4764
  onMouseDown: (e) => {
4746
- const t = e.target;
4747
- if (!t || t.tagName !== "INPUT" && t.tagName !== "BUTTON" && t.tagName !== "SELECT") {
4748
- e.preventDefault();
4749
- }
4765
+ if (!keepsOwnMouseDown(e.target)) e.preventDefault();
4750
4766
  },
4751
4767
  children: [
4752
4768
  /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "ed-toolbar-label", children: [
@@ -4837,10 +4853,7 @@ function TableMenu() {
4837
4853
  className: "ed-table-popover",
4838
4854
  role: "menu",
4839
4855
  onMouseDown: (e) => {
4840
- const t = e.target;
4841
- if (!t || t.tagName !== "INPUT" && t.tagName !== "BUTTON") {
4842
- e.preventDefault();
4843
- }
4856
+ if (!keepsOwnMouseDown(e.target)) e.preventDefault();
4844
4857
  },
4845
4858
  children: [
4846
4859
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
@@ -4946,6 +4959,37 @@ function TableMenu() {
4946
4959
  }
4947
4960
  )
4948
4961
  ] }),
4962
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("label", { className: "ed-toolbar-label ed-table-bgcolor", children: [
4963
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4964
+ "span",
4965
+ {
4966
+ className: "ed-toolbar-swatch",
4967
+ "aria-hidden": true,
4968
+ style: { background: editor.getTableBorderColor() ?? import_core7.TABLE_BORDER_COLOR }
4969
+ }
4970
+ ),
4971
+ "Cor da borda",
4972
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4973
+ "input",
4974
+ {
4975
+ type: "color",
4976
+ value: editor.getTableBorderColor() ?? import_core7.TABLE_BORDER_COLOR,
4977
+ onChange: (e) => editor.setTableBorderColor(e.target.value),
4978
+ "aria-label": "Cor da borda"
4979
+ }
4980
+ )
4981
+ ] }),
4982
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4983
+ "button",
4984
+ {
4985
+ type: "button",
4986
+ onClick: () => {
4987
+ setOpen(false);
4988
+ editor.setTableBorderColor(null);
4989
+ },
4990
+ children: "Restaurar cor padr\xE3o"
4991
+ }
4992
+ ),
4949
4993
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("hr", {}),
4950
4994
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
4951
4995
  "button",