@farm.js/react 0.1.0-beta.36 → 0.1.0-beta.37

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.
@@ -4597,13 +4597,7 @@ function reconcileCompilerKeyedMapUpdate(props, dirtyState, collectionToken, ins
4597
4597
  }
4598
4598
  }
4599
4599
  applyKeyedRowBindings(props, instance, item, index);
4600
- const conditionalValues = conditionals?.readValues(props, item, index) || EMPTY_KEYED_ROW_CONDITIONAL_VALUES;
4601
- for (const [id, values] of conditionalValues) {
4602
- if (conditionals?.changed(instance.conditionalValues.get(id), values)) {
4603
- conditionalChanges.push({ key, id, item, index });
4604
- }
4605
- }
4606
- instance.conditionalValues = conditionalValues;
4600
+ conditionals?.refresh(props, instance, key, item, index, conditionalChanges);
4607
4601
  instance.item = item;
4608
4602
  }
4609
4603
  return {
@@ -6018,6 +6012,7 @@ function reconcileCompilerKeyedArrayFilter(props, dirtyState, collectionToken, i
6018
6012
  for (const instance of instances.values()) instance.index = index++;
6019
6013
  return instances;
6020
6014
  }
6015
+ var renderKeyedRowConditional = (item, index, _id, render) => render(item, index);
6021
6016
  function createKeyedRowConditionalRuntime() {
6022
6017
  class FarmKeyedRowConditional extends React.Component {
6023
6018
  constructor() {
@@ -6060,30 +6055,48 @@ function createKeyedRowConditionalRuntime() {
6060
6055
  }
6061
6056
  }
6062
6057
  FarmKeyedRowConditional.displayName = "FarmCompiledKeyedRowConditional";
6063
- return {
6064
- element: (props) => React.createElement(FarmKeyedRowConditional, {
6065
- key: `${props.rowKey}:${props.id}`,
6066
- ...props
6067
- }),
6068
- readValues: readKeyedRowConditionalValues,
6069
- changed: keyedRowConditionalChanged,
6070
- owner: (listeners) => ({
6071
- subscribe(key, id, refresh) {
6072
- let row = listeners.get(key);
6073
- if (!row) {
6074
- row = /* @__PURE__ */ new Map();
6075
- listeners.set(key, row);
6058
+ class ConditionalBlock {
6059
+ constructor(context) {
6060
+ this.context = context;
6061
+ this.listeners = /* @__PURE__ */ new Map();
6062
+ this.owner = {
6063
+ subscribe: (key, id, refresh) => {
6064
+ let row = this.listeners.get(key);
6065
+ if (!row) {
6066
+ row = /* @__PURE__ */ new Map();
6067
+ this.listeners.set(key, row);
6068
+ }
6069
+ row.set(id, refresh);
6070
+ return () => {
6071
+ const current = this.listeners.get(key);
6072
+ if (current?.get(id) !== refresh) return;
6073
+ current.delete(id);
6074
+ if (current.size === 0) this.listeners.delete(key);
6075
+ };
6076
6076
  }
6077
- row.set(id, refresh);
6078
- return () => {
6079
- const current = listeners.get(key);
6080
- if (current?.get(id) !== refresh) return;
6081
- current.delete(id);
6082
- if (current.size === 0) listeners.delete(key);
6083
- };
6077
+ };
6078
+ this.render = (item, index, id, render) => {
6079
+ if (this.context.state.fallback) return render(item, index);
6080
+ const rowKey = keyedRowIdentity(this.context.currentProps.rowKey(item, index));
6081
+ return React.createElement(FarmKeyedRowConditional, {
6082
+ key: `${rowKey}:${id}`,
6083
+ owner: this.owner,
6084
+ rowKey,
6085
+ id,
6086
+ renderVersion: this.context.renderVersion,
6087
+ item,
6088
+ index,
6089
+ render
6090
+ });
6091
+ };
6092
+ }
6093
+ prune(instances) {
6094
+ if (this.listeners.size === 0) return;
6095
+ for (const key of this.listeners.keys()) {
6096
+ if (!instances.has(key)) this.listeners.delete(key);
6084
6097
  }
6085
- }),
6086
- notify(listeners, changes, afterCommit) {
6098
+ }
6099
+ notify(changes, afterCommit) {
6087
6100
  let pending = changes.length;
6088
6101
  const committed = () => {
6089
6102
  pending -= 1;
@@ -6091,12 +6104,25 @@ function createKeyedRowConditionalRuntime() {
6091
6104
  };
6092
6105
  flushSync(() => {
6093
6106
  for (const change of changes) {
6094
- const refresh = listeners.get(change.key)?.get(change.id);
6107
+ const refresh = this.listeners.get(change.key)?.get(change.id);
6095
6108
  if (refresh) refresh(change.item, change.index, committed);
6096
6109
  else committed();
6097
6110
  }
6098
6111
  });
6099
6112
  }
6113
+ }
6114
+ return {
6115
+ create: (context) => new ConditionalBlock(context),
6116
+ readValues: readKeyedRowConditionalValues,
6117
+ refresh(props, instance, key, item, index, changes) {
6118
+ const values = readKeyedRowConditionalValues(props, item, index);
6119
+ for (const [id, next] of values) {
6120
+ if (keyedRowConditionalChanged(instance.conditionalValues.get(id), next)) {
6121
+ changes.push({ key, id, item, index });
6122
+ }
6123
+ }
6124
+ instance.conditionalValues = values;
6125
+ }
6100
6126
  };
6101
6127
  }
6102
6128
  function createKeyedRowHostRuntime() {
@@ -6126,11 +6152,10 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6126
6152
  this.keyedTargets = options.keyedTargets?.(this.props);
6127
6153
  this.renderVersion = 0;
6128
6154
  this.eventHandlers = /* @__PURE__ */ new Map();
6129
- this.conditionalListeners = /* @__PURE__ */ new Map();
6155
+ this.conditionals = options.conditionals?.create(this);
6130
6156
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6131
6157
  // False after a rebuild without delegated events left surviving rows unindexed.
6132
6158
  this.elementIndexComplete = true;
6133
- this.conditionalOwner = options.conditionals?.owner(this.conditionalListeners);
6134
6159
  this.captureRoot = (root) => {
6135
6160
  this.root = root;
6136
6161
  };
@@ -6185,18 +6210,6 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6185
6210
  if (event.isPropagationStopped()) break;
6186
6211
  }
6187
6212
  };
6188
- this.rowConditional = (item, index, conditionalId, render) => {
6189
- if (this.state.fallback || !options.conditionals) return render(item, index);
6190
- return options.conditionals.element({
6191
- owner: this.conditionalOwner,
6192
- rowKey: keyedRowIdentity(this.currentProps.rowKey(item, index)),
6193
- id: conditionalId,
6194
- renderVersion: this.renderVersion,
6195
- item,
6196
- index,
6197
- render
6198
- });
6199
- };
6200
6213
  this.refresh = (afterCommit, dirtyState) => {
6201
6214
  if (dirtyState && options.keyedUpdates && this.mounted && this.root && !this.state.fallback) {
6202
6215
  const result = options.keyedUpdates.reconcile(
@@ -6250,7 +6263,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6250
6263
  this.instances = positionedInstances;
6251
6264
  this.rebuildElementIndex(this.instances);
6252
6265
  this.pruneEventHandlers();
6253
- this.pruneConditionalListeners();
6266
+ this.conditionals?.prune(this.instances);
6254
6267
  }
6255
6268
  this.commitCurrentCollection(dirtyState);
6256
6269
  afterCommit?.();
@@ -6270,7 +6283,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6270
6283
  if (removedRows) {
6271
6284
  this.rebuildElementIndex(this.instances);
6272
6285
  this.pruneEventHandlers();
6273
- this.pruneConditionalListeners();
6286
+ this.conditionals?.prune(this.instances);
6274
6287
  }
6275
6288
  this.commitCurrentCollection(dirtyState);
6276
6289
  afterCommit?.();
@@ -6296,12 +6309,12 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6296
6309
  }
6297
6310
  for (const key of delta.removedKeys) {
6298
6311
  this.eventHandlers.delete(key);
6299
- this.conditionalListeners.delete(key);
6312
+ this.conditionals?.listeners.delete(key);
6300
6313
  }
6301
6314
  } else {
6302
6315
  this.rebuildElementIndex(this.instances);
6303
6316
  this.pruneEventHandlers();
6304
- this.pruneConditionalListeners();
6317
+ this.conditionals?.prune(this.instances);
6305
6318
  }
6306
6319
  this.commitCurrentCollection(dirtyState);
6307
6320
  afterCommit?.();
@@ -6318,7 +6331,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6318
6331
  this.instances = filteredInstances;
6319
6332
  if (!this.elementIndexComplete) this.rebuildElementIndex(this.instances);
6320
6333
  this.pruneEventHandlers();
6321
- this.pruneConditionalListeners();
6334
+ this.conditionals?.prune(this.instances);
6322
6335
  this.commitCurrentCollection(dirtyState);
6323
6336
  afterCommit?.();
6324
6337
  return;
@@ -6467,12 +6480,6 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6467
6480
  if (!this.instances.has(key)) this.eventHandlers.delete(key);
6468
6481
  }
6469
6482
  }
6470
- pruneConditionalListeners() {
6471
- if (this.conditionalListeners.size === 0) return;
6472
- for (const key of this.conditionalListeners.keys()) {
6473
- if (!this.instances.has(key)) this.conditionalListeners.delete(key);
6474
- }
6475
- }
6476
6483
  commitCurrentCollection(dirtyState) {
6477
6484
  this.collectionToken = options.keyedUpdates?.commit(
6478
6485
  this.currentProps.items(),
@@ -6527,7 +6534,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6527
6534
  this.reactElements = elements;
6528
6535
  this.rebuildElementIndex(instances);
6529
6536
  this.pruneEventHandlers();
6530
- this.pruneConditionalListeners();
6537
+ this.conditionals?.prune(this.instances);
6531
6538
  this.commitCurrentCollection();
6532
6539
  return true;
6533
6540
  }
@@ -6564,7 +6571,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6564
6571
  }
6565
6572
  notifyConditionalChanges(changes, afterCommit) {
6566
6573
  if (changes.length === 0) afterCommit?.();
6567
- else options.conditionals.notify(this.conditionalListeners, changes, afterCommit);
6574
+ else this.conditionals.notify(changes, afterCommit);
6568
6575
  }
6569
6576
  refreshDirtyBindings(dirtyState, afterCommit) {
6570
6577
  if (!this.mounted || !this.root || this.state.fallback || this.hasReactOwnedRows() || this.currentProps.hostBlocks || !this.currentProps.structureDependencies || this.currentProps.structureDependencies.some((dependency) => dirtyState.has(dependency)) || this.currentProps.bindings.some((binding) => binding.dependencies === void 0)) {
@@ -6681,24 +6688,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6681
6688
  } else {
6682
6689
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6683
6690
  }
6684
- if (options.conditionals) {
6685
- const conditionalValues = this.readConditionalValues(
6686
- this.currentProps,
6687
- rows.items[index],
6688
- index
6689
- );
6690
- for (const [id, values] of conditionalValues) {
6691
- if (options.conditionals.changed(existing.conditionalValues.get(id), values)) {
6692
- conditionalChanges.push({
6693
- key,
6694
- id,
6695
- item: rows.items[index],
6696
- index
6697
- });
6698
- }
6699
- }
6700
- existing.conditionalValues = conditionalValues;
6701
- }
6691
+ options.conditionals?.refresh(
6692
+ this.currentProps,
6693
+ existing,
6694
+ key,
6695
+ rows.items[index],
6696
+ index,
6697
+ conditionalChanges
6698
+ );
6702
6699
  existing.item = rows.items[index];
6703
6700
  existing.index = index;
6704
6701
  }
@@ -6805,22 +6802,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6805
6802
  } else {
6806
6803
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6807
6804
  }
6808
- const conditionalValues = this.readConditionalValues(
6805
+ options.conditionals?.refresh(
6809
6806
  this.currentProps,
6807
+ existing,
6808
+ key,
6810
6809
  rows.items[index],
6811
- index
6810
+ index,
6811
+ conditionalChanges
6812
6812
  );
6813
- for (const [id, values] of conditionalValues) {
6814
- if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
6815
- conditionalChanges.push({
6816
- key,
6817
- id,
6818
- item: rows.items[index],
6819
- index
6820
- });
6821
- }
6822
- }
6823
- existing.conditionalValues = conditionalValues;
6824
6813
  existing.item = rows.items[index];
6825
6814
  existing.index = index;
6826
6815
  }
@@ -6829,7 +6818,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6829
6818
  instance.element.remove();
6830
6819
  this.instances.delete(instance.key);
6831
6820
  this.eventHandlers.delete(instance.key);
6832
- this.conditionalListeners.delete(instance.key);
6821
+ this.conditionals?.listeners.delete(instance.key);
6833
6822
  }
6834
6823
  this.commitCurrentCollection(dirtyState);
6835
6824
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
@@ -6870,7 +6859,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6870
6859
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
6871
6860
  this.elementIndexComplete = true;
6872
6861
  this.eventHandlers.clear();
6873
- this.conditionalListeners.clear();
6862
+ this.conditionals?.listeners.clear();
6874
6863
  this.commitCurrentCollection(dirtyState);
6875
6864
  afterCommit?.();
6876
6865
  return;
@@ -6934,22 +6923,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
6934
6923
  } else {
6935
6924
  applyKeyedRowBindings(this.currentProps, existing, rows.items[index], index);
6936
6925
  }
6937
- const conditionalValues = this.readConditionalValues(
6926
+ options.conditionals?.refresh(
6938
6927
  this.currentProps,
6928
+ existing,
6929
+ key,
6939
6930
  rows.items[index],
6940
- index
6931
+ index,
6932
+ conditionalChanges
6941
6933
  );
6942
- for (const [id, values] of conditionalValues) {
6943
- if (options.conditionals?.changed(existing.conditionalValues.get(id), values)) {
6944
- conditionalChanges.push({
6945
- key,
6946
- id,
6947
- item: rows.items[index],
6948
- index
6949
- });
6950
- }
6951
- }
6952
- existing.conditionalValues = conditionalValues;
6953
6934
  existing.item = rows.items[index];
6954
6935
  existing.index = index;
6955
6936
  nextInstances.push(existing);
@@ -7012,7 +6993,7 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
7012
6993
  this.rebuildElementIndex(this.instances);
7013
6994
  }
7014
6995
  this.pruneEventHandlers();
7015
- this.pruneConditionalListeners();
6996
+ this.conditionals?.prune(this.instances);
7016
6997
  this.commitCurrentCollection(dirtyState);
7017
6998
  this.notifyConditionalChanges(conditionalChanges, afterCommit);
7018
6999
  }
@@ -7085,11 +7066,14 @@ function createKeyedRowsBlockComponentCore(owner, options = {}) {
7085
7066
  this.instancesByElement = /* @__PURE__ */ new WeakMap();
7086
7067
  this.elementIndexComplete = true;
7087
7068
  this.eventHandlers.clear();
7088
- this.conditionalListeners.clear();
7069
+ this.conditionals?.listeners.clear();
7089
7070
  }
7090
7071
  render() {
7091
7072
  this.renderVersion += 1;
7092
- const container = this.currentProps.render(this.rowEvent, this.rowConditional);
7073
+ const container = this.currentProps.render(
7074
+ this.rowEvent,
7075
+ this.conditionals?.render || renderKeyedRowConditional
7076
+ );
7093
7077
  if (!React.isValidElement(container) || typeof container.type !== "string") {
7094
7078
  throw new TypeError(
7095
7079
  `Compiled keyed rows ${this.currentProps.id} must own one host container.`