@octaviaflow/core 3.1.0-beta.104 → 3.1.0-beta.106

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) => {
@@ -34711,8 +34717,18 @@ function ExpressionField({
34711
34717
  } else {
34712
34718
  el.className = CHIP;
34713
34719
  el.setAttribute("data-call", segment.name);
34714
- el.textContent = chipText(segment.name, segment.args);
34715
34720
  el.title = segment.raw;
34721
+ const text = document.createElement("span");
34722
+ text.className = "ods-expression-field__chip-text";
34723
+ text.textContent = chipText(segment.name, segment.args);
34724
+ el.appendChild(text);
34725
+ const open = document.createElement("span");
34726
+ open.className = "ods-expression-field__chip-open";
34727
+ open.setAttribute("data-open", "true");
34728
+ open.setAttribute("role", "button");
34729
+ open.setAttribute("aria-label", "Edit arguments");
34730
+ open.textContent = "\u2304";
34731
+ el.appendChild(open);
34716
34732
  }
34717
34733
  return el;
34718
34734
  },
@@ -34724,7 +34740,7 @@ function ExpressionField({
34724
34740
  if (!el) return;
34725
34741
  el.innerHTML = "";
34726
34742
  if (!raw) return;
34727
- for (const segment of parseExpression(raw, pillEveryToken)) {
34743
+ for (const segment of parseExpression(raw, pillEveryTokenRef.current)) {
34728
34744
  if (segment.kind === "text") {
34729
34745
  el.appendChild(document.createTextNode(segment.raw));
34730
34746
  continue;
@@ -34736,7 +34752,7 @@ function ExpressionField({
34736
34752
  }
34737
34753
  }
34738
34754
  },
34739
- [pillEveryToken, makeToken]
34755
+ [makeToken]
34740
34756
  );
34741
34757
  useEffect56(() => {
34742
34758
  if (fromSelf.current) {
@@ -34837,7 +34853,9 @@ function ExpressionField({
34837
34853
  const call = parseCall(raw);
34838
34854
  if (!call) return;
34839
34855
  editing.el.setAttribute("data-value", raw);
34840
- editing.el.textContent = chipText(call.name, call.args);
34856
+ const text = editing.el.querySelector(".ods-expression-field__chip-text");
34857
+ if (text) text.textContent = chipText(call.name, call.args);
34858
+ else editing.el.textContent = chipText(call.name, call.args);
34841
34859
  editing.el.title = raw;
34842
34860
  setEditing(null);
34843
34861
  commit();
@@ -34845,14 +34863,19 @@ function ExpressionField({
34845
34863
  },
34846
34864
  [editing, chipText, commit]
34847
34865
  );
34866
+ const handleMouseDown = useCallback50((e) => {
34867
+ const token = e.target.closest(`.${PILL}, .${CHIP}`);
34868
+ if (token) e.preventDefault();
34869
+ }, []);
34848
34870
  const handleClick = useCallback50(
34849
34871
  (e) => {
34850
- const target = e.target.closest(`.${PILL}, .${CHIP}`);
34872
+ const node = e.target;
34873
+ const target = node.closest(`.${PILL}, .${CHIP}`);
34851
34874
  if (!target) return;
34852
- selectToken(target);
34853
- if (!disabled && target.classList.contains(CHIP) && e.detail >= 2) {
34854
- openEditor(target);
34855
- }
34875
+ const chipEl = target;
34876
+ const wantsEditor = chipEl.classList.contains(CHIP) && (!!node.closest("[data-open]") || e.detail >= 2);
34877
+ selectToken(chipEl);
34878
+ if (!disabled && wantsEditor) openEditor(chipEl);
34856
34879
  },
34857
34880
  [disabled, openEditor, selectToken]
34858
34881
  );
@@ -34958,6 +34981,7 @@ function ExpressionField({
34958
34981
  style: { minHeight: `${Math.max(1, rows) * 1.5 + 1}rem` },
34959
34982
  onInput: commit,
34960
34983
  onBlur: handleBlur,
34984
+ onMouseDown: handleMouseDown,
34961
34985
  onClick: handleClick,
34962
34986
  onKeyDown: handleKeyDown,
34963
34987
  onCopy: handleCopy,
@@ -35014,6 +35038,13 @@ function CallEditor({
35014
35038
  if (at) crumbs.push({ label: nameOf(at.name), path: path.slice(0, i) });
35015
35039
  }
35016
35040
  const setArg = (index, next) => setDraft((d) => replaceArgument(d, [...path, index], next));
35041
+ const removeArg = (index) => setDraft((d) => {
35042
+ const at = callAt(d, path);
35043
+ if (!at) return d;
35044
+ const next = at.args.filter((_, i) => i !== index);
35045
+ const rebuilt = path.length === 0 ? formatCall(at.name, next) : `${at.name}(${next.join(", ")})`;
35046
+ return path.length === 0 ? rebuilt : replaceArgument(d, path, rebuilt);
35047
+ });
35017
35048
  const dropInto = (index) => (e) => {
35018
35049
  const dropped = e.dataTransfer.getData("application/x-fx-insert");
35019
35050
  if (!dropped) return;
@@ -35073,7 +35104,20 @@ function CallEditor({
35073
35104
  return (
35074
35105
  // eslint-disable-next-line react/no-array-index-key
35075
35106
  /* @__PURE__ */ jsxs141("div", { className: "ods-expression-field__editor-row", children: [
35076
- /* @__PURE__ */ jsx147("span", { id: `arg-${index}-label`, children: rowLabel }),
35107
+ /* @__PURE__ */ jsxs141("span", { className: "ods-expression-field__editor-row-head", children: [
35108
+ /* @__PURE__ */ jsx147("span", { id: `arg-${index}-label`, children: rowLabel }),
35109
+ /* @__PURE__ */ jsx147(
35110
+ "button",
35111
+ {
35112
+ type: "button",
35113
+ className: "ods-expression-field__editor-remove",
35114
+ "aria-label": `Remove ${rowLabel}`,
35115
+ title: "Remove this argument",
35116
+ onClick: () => removeArg(index),
35117
+ children: "\u2715"
35118
+ }
35119
+ )
35120
+ ] }),
35077
35121
  nested ? /* @__PURE__ */ jsxs141(
35078
35122
  "div",
35079
35123
  {
@@ -35136,14 +35180,14 @@ function CallEditor({
35136
35180
  "button",
35137
35181
  {
35138
35182
  type: "button",
35139
- className: "ods-expression-field__editor-link",
35183
+ className: "ods-expression-field__editor-add",
35140
35184
  onClick: () => setDraft((d) => {
35141
35185
  const at = callAt(d, path);
35142
35186
  if (!at) return d;
35143
35187
  const next = [...at.args, '""'];
35144
35188
  return path.length === 0 ? formatCall(at.name, next) : replaceArgument(d, path, `${at.name}(${next.join(", ")})`);
35145
35189
  }),
35146
- children: "+ argument"
35190
+ children: "+ Add argument"
35147
35191
  }
35148
35192
  )
35149
35193
  ] }),