@farm.js/react 0.1.0-beta.31 → 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. */
@@ -1760,8 +1760,11 @@ var JAVASCRIPT_URL = (
1760
1760
  );
1761
1761
  var BLOCKS_JAVASCRIPT_URLS = Number.parseInt(React.version, 10) > 18;
1762
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
+ }
1763
1766
  const tag = element.localName;
1764
- 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;
1765
1768
  }
1766
1769
  function createConditionalBlockComponent(owner) {
1767
1770
  class FarmConditionalBlock extends React.Component {
@@ -2551,12 +2554,15 @@ function createKeyedRowInstance(props, document, key, item, index) {
2551
2554
  conditionalValues: EMPTY_KEYED_ROW_CONDITIONAL_VALUES
2552
2555
  };
2553
2556
  if (props.cloneRows) {
2554
- const targets = [];
2557
+ let targets = props.targets?.(element);
2555
2558
  let found = true;
2556
- for (const binding of props.bindings) {
2557
- const target = findCompilerHostTarget(element, binding.path);
2558
- found && (found = target !== null);
2559
- 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
+ }
2560
2566
  }
2561
2567
  if (found) instance.targets = targets;
2562
2568
  if (template) {
@@ -6148,14 +6154,18 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6148
6154
  const eventTarget = event.target;
6149
6155
  if (!instance || !eventTarget) return;
6150
6156
  const capture = name.endsWith("Capture");
6151
- const matches = (this.currentProps.events || []).filter((descriptor) => descriptor.name === name && descriptor.path !== void 0).map((descriptor) => ({
6152
- descriptor,
6153
- target: findCompilerHostTarget(instance.element, descriptor.path || [])
6154
- })).filter(
6155
- (match) => Boolean(
6156
- match.target && (match.target === eventTarget || match.target.contains(eventTarget))
6157
- )
6158
- ).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(
6159
6169
  (left, right) => capture ? (left.descriptor.path?.length || 0) - (right.descriptor.path?.length || 0) : (right.descriptor.path?.length || 0) - (left.descriptor.path?.length || 0)
6160
6170
  );
6161
6171
  for (const match of matches) {
@@ -6879,10 +6889,12 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6879
6889
  let oldIndex = 0;
6880
6890
  for (const key of this.instances.keys()) oldIndices.set(key, oldIndex++);
6881
6891
  }
6882
- for (const [key, instance] of this.instances) {
6883
- if (!nextKeys.has(key)) {
6884
- instance.scope?.cleanup();
6885
- 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
+ }
6886
6898
  }
6887
6899
  }
6888
6900
  const sequence = hasSurvivingRows ? rows.keys.map((key) => oldIndices.get(key) ?? -1) : [];