@farm.js/react 0.1.0-beta.30 → 0.1.0-beta.32

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.
@@ -276,6 +276,8 @@ interface CompilerKeyedRowsBlockProps {
276
276
  * row can be cloned from one already built with its bindings reapplied.
277
277
  */
278
278
  cloneRows?: boolean;
279
+ /** Compiler-emitted lookup sharing plain-row binding path prefixes. */
280
+ targets?: (root: Element) => (Element | null)[];
279
281
  }
280
282
  interface CompilerKeyedRange {
281
283
  /** Number of static direct host siblings between this range and the previous range. */
@@ -276,6 +276,8 @@ interface CompilerKeyedRowsBlockProps {
276
276
  * row can be cloned from one already built with its bindings reapplied.
277
277
  */
278
278
  cloneRows?: boolean;
279
+ /** Compiler-emitted lookup sharing plain-row binding path prefixes. */
280
+ targets?: (root: Element) => (Element | null)[];
279
281
  }
280
282
  interface CompilerKeyedRange {
281
283
  /** Number of static direct host siblings between this range and the previous range. */
@@ -1725,6 +1725,9 @@ function updateAttribute(element, name, value) {
1725
1725
  if (name === "value" && (isInputElement(element) || isTextAreaElement(element))) {
1726
1726
  const nextValue = value === null || value === void 0 ? "" : String(value);
1727
1727
  if (element.value !== nextValue) element.value = nextValue;
1728
+ if (value != null && isInputElement(element) && (element.type !== "number" || element.ownerDocument.activeElement !== element) && element.defaultValue !== nextValue) {
1729
+ element.defaultValue = nextValue;
1730
+ }
1728
1731
  return;
1729
1732
  }
1730
1733
  if (name === "value" && isSelectElement(element)) {
@@ -1757,8 +1760,11 @@ var JAVASCRIPT_URL = (
1757
1760
  );
1758
1761
  var BLOCKS_JAVASCRIPT_URLS = Number.parseInt(React.version, 10) > 18;
1759
1762
  function compilerAttributeValue(element, name, value) {
1763
+ if (!BLOCKS_JAVASCRIPT_URLS || name !== "href" && name !== "src" && name !== "action" && name !== "formAction" && name !== "data") {
1764
+ return value;
1765
+ }
1760
1766
  const tag = element.localName;
1761
- return BLOCKS_JAVASCRIPT_URLS && (name === "href" || name === "src" || name === "action" || name === "formAction" || name === "data" && tag === "object") && !tag.includes("-") && JAVASCRIPT_URL.test(value) ? "javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')" : value;
1767
+ return (name !== "data" || tag === "object") && !tag.includes("-") && JAVASCRIPT_URL.test(value) ? "javascript:throw new Error('React has blocked a javascript: URL as a security precaution.')" : value;
1762
1768
  }
1763
1769
  function createConditionalBlockComponent(owner) {
1764
1770
  class FarmConditionalBlock extends React.Component {
@@ -2548,12 +2554,15 @@ function createKeyedRowInstance(props, document, key, item, index) {
2548
2554
  conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2549
2555
  };
2550
2556
  if (props.cloneRows) {
2551
- const targets = [];
2557
+ let targets = props.targets?.(element);
2552
2558
  let found = true;
2553
- for (const binding of props.bindings) {
2554
- const target = findCompilerHostTarget(element, binding.path);
2555
- found && (found = target !== null);
2556
- targets.push(target);
2559
+ if (!targets || targets.length !== props.bindings.length || !props.bindings.every((_, index2) => targets[index2] != null)) {
2560
+ targets = [];
2561
+ for (const binding of props.bindings) {
2562
+ const target = findCompilerHostTarget(element, binding.path);
2563
+ found && (found = target !== null);
2564
+ targets.push(target);
2565
+ }
2557
2566
  }
2558
2567
  if (found) instance.targets = targets;
2559
2568
  if (template) {
@@ -6145,14 +6154,18 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6145
6154
  const eventTarget = event.target;
6146
6155
  if (!instance || !eventTarget) return;
6147
6156
  const capture = name.endsWith("Capture");
6148
- const matches = (this.currentProps.events || []).filter((descriptor) => descriptor.name === name && descriptor.path !== void 0).map((descriptor) => ({
6149
- descriptor,
6150
- target: findCompilerHostTarget(instance.element, descriptor.path || [])
6151
- })).filter(
6152
- (match) => Boolean(
6153
- match.target && (match.target === eventTarget || match.target.contains(eventTarget))
6154
- )
6155
- ).sort(
6157
+ const descriptors = this.currentProps.events || [];
6158
+ const matches = [];
6159
+ for (let index = 0, length = descriptors.length; index < length; index += 1) {
6160
+ if (!(index in descriptors)) continue;
6161
+ const descriptor = descriptors[index];
6162
+ if (descriptor.name !== name || descriptor.path === void 0) continue;
6163
+ const target = findCompilerHostTarget(instance.element, descriptor.path || []);
6164
+ if (target && (target === eventTarget || target.contains(eventTarget))) {
6165
+ matches.push({ descriptor, target });
6166
+ }
6167
+ }
6168
+ matches.sort(
6156
6169
  (left, right) => capture ? (left.descriptor.path?.length || 0) - (right.descriptor.path?.length || 0) : (right.descriptor.path?.length || 0) - (left.descriptor.path?.length || 0)
6157
6170
  );
6158
6171
  for (const match of matches) {
@@ -6876,10 +6889,12 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6876
6889
  let oldIndex = 0;
6877
6890
  for (const key of this.instances.keys()) oldIndices.set(key, oldIndex++);
6878
6891
  }
6879
- for (const [key, instance] of this.instances) {
6880
- if (!nextKeys.has(key)) {
6881
- instance.scope?.cleanup();
6882
- if (hasSurvivingRows) instance.element.remove();
6892
+ if (hasSurvivingRows || options.hostBlocks) {
6893
+ for (const [key, instance] of this.instances) {
6894
+ if (!nextKeys.has(key)) {
6895
+ instance.scope?.cleanup();
6896
+ if (hasSurvivingRows) instance.element.remove();
6897
+ }
6883
6898
  }
6884
6899
  }
6885
6900
  const sequence = hasSurvivingRows ? rows.keys.map((key) => oldIndices.get(key) ?? -1) : [];