@octaviaflow/core 3.1.0-beta.105 → 3.1.0-beta.107

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
@@ -34682,13 +34682,19 @@ function ExpressionField({
34682
34682
  const fieldId = id ?? generatedId;
34683
34683
  const helperId = `${fieldId}-helper`;
34684
34684
  const [editing, setEditing] = useState71(null);
34685
+ const resolveLabelRef = useRef50(resolveLabel);
34686
+ const resolveCallRef = useRef50(resolveCall);
34687
+ const pillEveryTokenRef = useRef50(pillEveryToken);
34688
+ resolveLabelRef.current = resolveLabel;
34689
+ resolveCallRef.current = resolveCall;
34690
+ pillEveryTokenRef.current = pillEveryToken;
34685
34691
  const labelFor = useCallback50(
34686
- (token) => resolveLabel?.(token) ?? shortReferenceLabel(token),
34687
- [resolveLabel]
34692
+ (token) => resolveLabelRef.current?.(token) ?? shortReferenceLabel(token),
34693
+ []
34688
34694
  );
34689
34695
  const callLabel = useCallback50(
34690
- (name) => resolveCall?.(name)?.label ?? (name.startsWith("user.") ? name.slice(5) : name),
34691
- [resolveCall]
34696
+ (name) => resolveCallRef.current?.(name)?.label ?? (name.startsWith("user.") ? name.slice(5) : name),
34697
+ []
34692
34698
  );
34693
34699
  const chipText = useCallback50(
34694
34700
  (name, args) => {
@@ -34734,7 +34740,7 @@ function ExpressionField({
34734
34740
  if (!el) return;
34735
34741
  el.innerHTML = "";
34736
34742
  if (!raw) return;
34737
- for (const segment of parseExpression(raw, pillEveryToken)) {
34743
+ for (const segment of parseExpression(raw, pillEveryTokenRef.current)) {
34738
34744
  if (segment.kind === "text") {
34739
34745
  el.appendChild(document.createTextNode(segment.raw));
34740
34746
  continue;
@@ -34746,7 +34752,7 @@ function ExpressionField({
34746
34752
  }
34747
34753
  }
34748
34754
  },
34749
- [pillEveryToken, makeToken]
34755
+ [makeToken]
34750
34756
  );
34751
34757
  useEffect56(() => {
34752
34758
  if (fromSelf.current) {
@@ -34857,6 +34863,10 @@ function ExpressionField({
34857
34863
  },
34858
34864
  [editing, chipText, commit]
34859
34865
  );
34866
+ const handleMouseDown = useCallback50((e) => {
34867
+ const token = e.target.closest(`.${PILL}, .${CHIP}`);
34868
+ if (token) e.preventDefault();
34869
+ }, []);
34860
34870
  const handleClick = useCallback50(
34861
34871
  (e) => {
34862
34872
  const node = e.target;
@@ -34971,6 +34981,7 @@ function ExpressionField({
34971
34981
  style: { minHeight: `${Math.max(1, rows) * 1.5 + 1}rem` },
34972
34982
  onInput: commit,
34973
34983
  onBlur: handleBlur,
34984
+ onMouseDown: handleMouseDown,
34974
34985
  onClick: handleClick,
34975
34986
  onKeyDown: handleKeyDown,
34976
34987
  onCopy: handleCopy,
@@ -34985,6 +34996,7 @@ function ExpressionField({
34985
34996
  CallEditor,
34986
34997
  {
34987
34998
  raw: editing.raw,
34999
+ anchor: editing.el,
34988
35000
  rect: editing.rect,
34989
35001
  nameOf: callLabel,
34990
35002
  labelFor,
@@ -34999,6 +35011,7 @@ function ExpressionField({
34999
35011
  }
35000
35012
  function CallEditor({
35001
35013
  raw,
35014
+ anchor,
35002
35015
  rect,
35003
35016
  nameOf,
35004
35017
  labelFor,
@@ -35010,13 +35023,27 @@ function CallEditor({
35010
35023
  const [path, setPath] = useState71([]);
35011
35024
  const [rawMode, setRawMode] = useState71(false);
35012
35025
  const panelRef = useRef50(null);
35026
+ const onApplyRef = useRef50(onApply);
35027
+ onApplyRef.current = onApply;
35028
+ const draftRef = useRef50(draft);
35029
+ draftRef.current = draft;
35013
35030
  useEffect56(() => {
35014
35031
  const onKey = (e) => {
35015
35032
  if (e.key === "Escape") onCancel();
35016
35033
  };
35034
+ const onPointerDown = (e) => {
35035
+ const target = e.target;
35036
+ if (panelRef.current?.contains(target)) return;
35037
+ if (anchor.contains(target)) return;
35038
+ onApplyRef.current(draftRef.current);
35039
+ };
35017
35040
  document.addEventListener("keydown", onKey);
35018
- return () => document.removeEventListener("keydown", onKey);
35019
- }, [onCancel]);
35041
+ document.addEventListener("mousedown", onPointerDown, true);
35042
+ return () => {
35043
+ document.removeEventListener("keydown", onKey);
35044
+ document.removeEventListener("mousedown", onPointerDown, true);
35045
+ };
35046
+ }, [anchor, onCancel]);
35020
35047
  const current = callAt(draft, path);
35021
35048
  const signature = current ? resolveCall?.(current.name) : void 0;
35022
35049
  const names = signature?.args ?? [];
@@ -35027,6 +35054,13 @@ function CallEditor({
35027
35054
  if (at) crumbs.push({ label: nameOf(at.name), path: path.slice(0, i) });
35028
35055
  }
35029
35056
  const setArg = (index, next) => setDraft((d) => replaceArgument(d, [...path, index], next));
35057
+ const removeArg = (index) => setDraft((d) => {
35058
+ const at = callAt(d, path);
35059
+ if (!at) return d;
35060
+ const next = at.args.filter((_, i) => i !== index);
35061
+ const rebuilt = path.length === 0 ? formatCall(at.name, next) : `${at.name}(${next.join(", ")})`;
35062
+ return path.length === 0 ? rebuilt : replaceArgument(d, path, rebuilt);
35063
+ });
35030
35064
  const dropInto = (index) => (e) => {
35031
35065
  const dropped = e.dataTransfer.getData("application/x-fx-insert");
35032
35066
  if (!dropped) return;
@@ -35086,7 +35120,20 @@ function CallEditor({
35086
35120
  return (
35087
35121
  // eslint-disable-next-line react/no-array-index-key
35088
35122
  /* @__PURE__ */ jsxs141("div", { className: "ods-expression-field__editor-row", children: [
35089
- /* @__PURE__ */ jsx147("span", { id: `arg-${index}-label`, children: rowLabel }),
35123
+ /* @__PURE__ */ jsxs141("span", { className: "ods-expression-field__editor-row-head", children: [
35124
+ /* @__PURE__ */ jsx147("span", { id: `arg-${index}-label`, children: rowLabel }),
35125
+ /* @__PURE__ */ jsx147(
35126
+ "button",
35127
+ {
35128
+ type: "button",
35129
+ className: "ods-expression-field__editor-remove",
35130
+ "aria-label": `Remove ${rowLabel}`,
35131
+ title: "Remove this argument",
35132
+ onClick: () => removeArg(index),
35133
+ children: "\u2715"
35134
+ }
35135
+ )
35136
+ ] }),
35090
35137
  nested ? /* @__PURE__ */ jsxs141(
35091
35138
  "div",
35092
35139
  {
@@ -35149,14 +35196,14 @@ function CallEditor({
35149
35196
  "button",
35150
35197
  {
35151
35198
  type: "button",
35152
- className: "ods-expression-field__editor-link",
35199
+ className: "ods-expression-field__editor-add",
35153
35200
  onClick: () => setDraft((d) => {
35154
35201
  const at = callAt(d, path);
35155
35202
  if (!at) return d;
35156
35203
  const next = [...at.args, '""'];
35157
35204
  return path.length === 0 ? formatCall(at.name, next) : replaceArgument(d, path, `${at.name}(${next.join(", ")})`);
35158
35205
  }),
35159
- children: "+ argument"
35206
+ children: "+ Add argument"
35160
35207
  }
35161
35208
  )
35162
35209
  ] }),