Skip to content

Commit

Permalink
Consistent repeat terminology: “sequence” -> “range”
Browse files Browse the repository at this point in the history
  • Loading branch information
eyelidlessness committed May 28, 2024
1 parent f6f8b3d commit 475b3cc
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const groupNode = (node: GroupNode | RepeatRangeNode): GroupNode | null => {

export const XFormGroup = (props: XFormGroupProps) => {
const groupLabel = () => {
if (props.node.definition.type === 'repeat-sequence') {
if (props.node.nodeType === 'repeat-range') {
return null;
}

Expand Down
12 changes: 9 additions & 3 deletions packages/web-forms/src/components/QuestionList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,17 @@ import RepeatRange from './RepeatRange.vue';
defineProps<{ nodes: readonly GeneralChildNode[]}>();
const isLeafNode = (n: GeneralChildNode) : n is AnyLeafNode => n.definition.type === 'value-node';
const isGroupNode = (n: GeneralChildNode) : n is GroupNode => n.definition.type === 'subtree';
const isRepeatRangeNode = (n: GeneralChildNode) : n is RepeatRangeNode => n.definition.type === 'repeat-sequence';
const isLeafNode = (node: GeneralChildNode): node is AnyLeafNode => {
return node.nodeType === 'string' || node.nodeType === 'select';
};
const isGroupNode = (node: GeneralChildNode): node is GroupNode => {
return node.nodeType === 'group';
};
const isRepeatRangeNode = (node: GeneralChildNode): node is RepeatRangeNode => {
return node.nodeType === 'repeat-range';
};
</script>

<template>
Expand Down
4 changes: 2 additions & 2 deletions packages/xforms-engine/src/client/RepeatRangeNode.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { RepeatSequenceDefinition } from '../model/RepeatSequenceDefinition.ts';
import type { RepeatRangeDefinition } from '../model/RepeatRangeDefinition.ts';
import type { BaseNode, BaseNodeState } from './BaseNode.ts';
import type { RepeatInstanceNode } from './RepeatInstanceNode.ts';
import type { RootNode } from './RootNode.ts';
Expand Down Expand Up @@ -89,7 +89,7 @@ export interface RepeatRangeNodeState extends BaseNodeState {
*/
export interface RepeatRangeNode extends BaseNode {
readonly nodeType: 'repeat-range';
readonly definition: RepeatSequenceDefinition;
readonly definition: RepeatRangeDefinition;
readonly root: RootNode;
readonly parent: GeneralParentNode;
readonly currentState: RepeatRangeNodeState;
Expand Down
6 changes: 3 additions & 3 deletions packages/xforms-engine/src/instance/RepeatRange.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type { EngineState } from '../lib/reactivity/node-state/createEngineState
import type { SharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
import { createSharedNodeState } from '../lib/reactivity/node-state/createSharedNodeState.ts';
import { createNodeLabel } from '../lib/reactivity/text/createNodeLabel.ts';
import type { RepeatSequenceDefinition } from '../model/RepeatSequenceDefinition.ts';
import type { RepeatRangeDefinition } from '../model/RepeatRangeDefinition.ts';
import type { RepeatDefinition } from './RepeatInstance.ts';
import { RepeatInstance } from './RepeatInstance.ts';
import type { Root } from './Root.ts';
Expand All @@ -31,7 +31,7 @@ interface RepeatRangeStateSpec extends DescendantNodeSharedStateSpec {
}

export class RepeatRange
extends DescendantNode<RepeatSequenceDefinition, RepeatRangeStateSpec, RepeatInstance>
extends DescendantNode<RepeatRangeDefinition, RepeatRangeStateSpec, RepeatInstance>
implements RepeatRangeNode, EvaluationContext, SubscribableDependency
{
/**
Expand Down Expand Up @@ -69,7 +69,7 @@ export class RepeatRange

readonly currentState: MaterializedChildren<CurrentState<RepeatRangeStateSpec>, RepeatInstance>;

constructor(parent: GeneralParentNode, definition: RepeatSequenceDefinition) {
constructor(parent: GeneralParentNode, definition: RepeatRangeDefinition) {
super(parent, definition);

const childrenState = createChildrenState<RepeatRange, RepeatInstance>(this);
Expand Down
2 changes: 1 addition & 1 deletion packages/xforms-engine/src/instance/children.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export const buildChildren = (parent: GeneralParentNode): GeneralChildNode[] =>
return new Group(parent, child as GroupDefinition);
}

case 'repeat-sequence': {
case 'repeat-range': {
return new RepeatRange(parent, child);
}

Expand Down
20 changes: 10 additions & 10 deletions packages/xforms-engine/src/model/NodeDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { AnyBodyElementDefinition } from '../body/BodyDefinition.ts';
import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
import type { BindDefinition } from './BindDefinition.ts';
import type { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
import type { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
import type { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
import type { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';
import type { RootDefinition } from './RootDefinition.ts';
import type { SubtreeDefinition } from './SubtreeDefinition.ts';
Expand All @@ -17,13 +17,13 @@ import type { ValueNodeDefinition } from './ValueNodeDefinition.ts';
export type RootNodeType = 'root';

/**
* Corresponds to a sequence of model/entry DOM subtrees which in turn
* Corresponds to a range/sequence of model/entry DOM subtrees which in turn
* corresponds to a <repeat> in the form body definition.
*/
export type RepeatSequenceType = 'repeat-sequence';
export type RepeatRangeType = 'repeat-range';

/**
* Corresponds to a template definition for a repeat sequence, which either has
* Corresponds to a template definition for a repeat range, which either has
* an explicit `jr:template=""` attribute in the form definition or is inferred
* as a template from the form's first element matched by a <repeat nodeset>.
*/
Expand All @@ -32,7 +32,7 @@ export type RepeatTemplateType = 'repeat-template';
/**
* Corresponds to a single instance of a model/entry DOM subtree which
* in turn corresponds to a <repeat> in the form body definition, and a
* 'repeat-sequence' definition.
* 'repeat-range' definition.
*/
export type RepeatInstanceType = 'repeat-instance';

Expand All @@ -55,7 +55,7 @@ export type ValueNodeType = 'value-node';
export type NodeDefinitionType =
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
| RootNodeType
| RepeatSequenceType
| RepeatRangeType
| RepeatTemplateType
| RepeatInstanceType
| SubtreeNodeType
Expand All @@ -71,7 +71,7 @@ export type ParentNodeDefinition =

// prettier-ignore
export type ChildNodeDefinition =
| RepeatSequenceDefinition
| RepeatRangeDefinition
| SubtreeDefinition
| ValueNodeDefinition;

Expand All @@ -91,7 +91,7 @@ export type NodeChildren<Type extends NodeDefinitionType> =

// prettier-ignore
export type NodeInstances<Type extends NodeDefinitionType> =
Type extends 'repeat-sequence'
Type extends 'repeat-range'
? readonly RepeatInstanceDefinition[]
: null;

Expand All @@ -104,7 +104,7 @@ export type NodeParent<Type extends NodeDefinitionType> =
// TODO: value-node may be Attr
// prettier-ignore
export type ModelNode<Type extends NodeDefinitionType> =
Type extends 'repeat-sequence'
Type extends 'repeat-range'
? null
: Element;

Expand Down Expand Up @@ -137,7 +137,7 @@ export interface NodeDefinition<Type extends NodeDefinitionType> {
export type AnyNodeDefinition =
// eslint-disable-next-line @typescript-eslint/sort-type-constituents
| RootDefinition
| RepeatSequenceDefinition
| RepeatRangeDefinition
| RepeatTemplateDefinition
| RepeatInstanceDefinition
| SubtreeDefinition
Expand Down
10 changes: 5 additions & 5 deletions packages/xforms-engine/src/model/RepeatInstanceDefinition.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts';
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
import type { ChildNodeDefinition, NodeDefinition } from './NodeDefinition.ts';
import type { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
import type { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';

export class RepeatInstanceDefinition
extends DescendentNodeDefinition<'repeat-instance', RepeatElementDefinition>
Expand All @@ -15,19 +15,19 @@ export class RepeatInstanceDefinition
readonly defaultValue = null;

constructor(
protected readonly sequence: RepeatSequenceDefinition,
range: RepeatRangeDefinition,
readonly node: Element
) {
const { bind, bodyElement, parent, root } = sequence;
const { bind, bodyElement, parent, root } = range;

super(parent, bind, bodyElement);

this.nodeName = sequence.nodeName;
this.nodeName = range.nodeName;
this.children = root.buildSubtree(this);
}

toJSON() {
const { bind, bodyElement, parent, root, sequence, ...rest } = this;
const { bind, bodyElement, parent, root, ...rest } = this;

return rest;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { NodeDefinition, ParentNodeDefinition } from './NodeDefinition.ts';
import { RepeatInstanceDefinition } from './RepeatInstanceDefinition.ts';
import { RepeatTemplateDefinition } from './RepeatTemplateDefinition.ts';

export class RepeatSequenceDefinition
extends DescendentNodeDefinition<'repeat-sequence', RepeatElementDefinition>
implements NodeDefinition<'repeat-sequence'>
export class RepeatRangeDefinition
extends DescendentNodeDefinition<'repeat-range', RepeatElementDefinition>
implements NodeDefinition<'repeat-range'>
{
// TODO: if an implicit template is derived from an instance in a form
// definition, should its default values (if any) be cleared? Probably!
Expand All @@ -19,7 +19,7 @@ export class RepeatSequenceDefinition
return templateElement.cloneNode(true) as Element;
}

readonly type = 'repeat-sequence';
readonly type = 'repeat-range';

readonly template: RepeatTemplateDefinition;
readonly children = null;
Expand Down
14 changes: 7 additions & 7 deletions packages/xforms-engine/src/model/RepeatTemplateDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import type { RepeatElementDefinition } from '../body/RepeatElementDefinition.ts
import { BindDefinition } from './BindDefinition.ts';
import { DescendentNodeDefinition } from './DescendentNodeDefinition.ts';
import type { ChildNodeDefinition, NodeDefinition } from './NodeDefinition.ts';
import type { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
import type { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';

const repeatTemplates = new WeakMap<BindDefinition, RepeatTemplateDefinition>();

Expand Down Expand Up @@ -77,10 +77,10 @@ export class RepeatTemplateDefinition
implements NodeDefinition<'repeat-template'>
{
static parseModelNodes(
sequence: RepeatSequenceDefinition,
range: RepeatRangeDefinition,
modelNodes: readonly [Element, ...Element[]]
): ParsedRepeatNodes {
const { bind } = sequence;
const { bind } = range;

let template = repeatTemplates.get(bind);
let instanceNodes: readonly Element[];
Expand All @@ -89,7 +89,7 @@ export class RepeatTemplateDefinition
const [templateNode, ...rest] = splitInstanceNodes(modelNodes);

instanceNodes = rest;
template = new this(sequence, templateNode);
template = new this(range, templateNode);
} else {
// TODO: this is under the assumption that for any depth > 1, if a
// template has already been defined for the given form definition, any
Expand Down Expand Up @@ -121,10 +121,10 @@ export class RepeatTemplateDefinition
readonly defaultValue = null;

protected constructor(
protected readonly sequence: RepeatSequenceDefinition,
range: RepeatRangeDefinition,
protected readonly templateNode: ExplicitRepeatTemplateElement
) {
const { bind, bodyElement, parent, root } = sequence;
const { bind, bodyElement, parent, root } = range;

super(parent, bind, bodyElement);

Expand All @@ -138,7 +138,7 @@ export class RepeatTemplateDefinition
}

toJSON() {
const { bind, bodyElement, parent, root, sequence, ...rest } = this;
const { bind, bodyElement, parent, root, ...rest } = this;

return rest;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/xforms-engine/src/model/RootDefinition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import type {
NodeDefinition,
ParentNodeDefinition,
} from './NodeDefinition.ts';
import { RepeatSequenceDefinition } from './RepeatSequenceDefinition.ts';
import { RepeatRangeDefinition } from './RepeatRangeDefinition.ts';
import { SubtreeDefinition } from './SubtreeDefinition.ts';
import { ValueNodeDefinition } from './ValueNodeDefinition.ts';

Expand Down Expand Up @@ -87,7 +87,7 @@ export class RootDefinition implements NodeDefinition<'root'> {
const [firstChild, ...restChildren] = children;

if (bodyElement?.type === 'repeat') {
return new RepeatSequenceDefinition(parent, bind, bodyElement, children);
return new RepeatRangeDefinition(parent, bind, bodyElement, children);
}

if (restChildren.length) {
Expand Down
Loading

0 comments on commit 475b3cc

Please sign in to comment.