@docengine/editor 0.0.105 → 0.0.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.
Files changed (34) hide show
  1. package/README.md +5 -1
  2. package/lib/.tsbuildinfo +1 -1
  3. package/lib/create-editor.d.ts.map +1 -1
  4. package/lib/fields/inline-fields.d.ts +1 -1
  5. package/lib/index.d.ts +1 -1
  6. package/lib/index.d.ts.map +1 -1
  7. package/lib/index.js +1 -1
  8. package/lib/index.js.map +1 -1
  9. package/lib/ui/field-mapping-badges.test.js +11 -11
  10. package/lib/ui/field-mapping-badges.test.js.map +1 -1
  11. package/lib/ui/mapping-drag-drop.test.js +11 -11
  12. package/lib/ui/mapping-drag-drop.test.js.map +1 -1
  13. package/lib/ui/mapping-result-helper.d.ts +1 -1
  14. package/lib/ui/mapping-result-helper.d.ts.map +1 -1
  15. package/lib/ui/mapping-result-helper.js +32 -13
  16. package/lib/ui/mapping-result-helper.js.map +1 -1
  17. package/lib/ui/mapping-result-helper.test.js +58 -20
  18. package/lib/ui/mapping-result-helper.test.js.map +1 -1
  19. package/lib/ui/source-path-canvas-drop.test.js +28 -28
  20. package/lib/ui/source-path-canvas-drop.test.js.map +1 -1
  21. package/lib/ui/source-schema-tree.d.ts.map +1 -1
  22. package/lib/ui/source-schema-tree.js +4 -0
  23. package/lib/ui/source-schema-tree.js.map +1 -1
  24. package/package.json +1 -1
  25. package/src/index.ts +3 -0
  26. package/src/styles/editor.css +109 -87
  27. package/src/themes/bridge.css +134 -15
  28. package/src/themes/prime.css +128 -37
  29. package/src/ui/field-mapping-badges.test.ts +11 -11
  30. package/src/ui/mapping-drag-drop.test.ts +11 -11
  31. package/src/ui/mapping-result-helper.test.ts +61 -20
  32. package/src/ui/mapping-result-helper.ts +30 -12
  33. package/src/ui/source-path-canvas-drop.test.ts +32 -32
  34. package/src/ui/source-schema-tree.ts +3 -0
@@ -32,25 +32,66 @@ describe('mapping-result-helper', () => {
32
32
  });
33
33
 
34
34
  it('findPathTokenAtCursor locates partial path before cursor', () => {
35
- const value = '"city": "$payload.se';
35
+ const value = '"city": "se';
36
36
  const token = findPathTokenAtCursor(value, value.length);
37
- assert.deepEqual(token, { start: 9, end: 20, prefix: '$payload.se' });
37
+ assert.deepEqual(token, { start: 9, end: 11, prefix: 'se' });
38
+ });
39
+
40
+ it('findPathTokenAtCursor includes trailing dot for object drill-in', () => {
41
+ const value = '"Billing Address": "account_id."';
42
+ const start = value.indexOf('account_id.');
43
+ const cursor = start + 'account_id.'.length;
44
+ const token = findPathTokenAtCursor(value, cursor);
45
+ assert.deepEqual(token, {
46
+ start,
47
+ end: start + 'account_id.'.length,
48
+ prefix: 'account_id.',
49
+ });
50
+ });
51
+
52
+ it('resolveAutocompleteLookup lists children after account_id.', () => {
53
+ const payload = {
54
+ account_id: {
55
+ last_name: 'Ada',
56
+ billing_address: '1 Main',
57
+ },
58
+ name: 'Opp',
59
+ };
60
+ const value = '"Billing Address": "account_id."';
61
+ const cursor = value.indexOf('account_id.') + 'account_id.'.length;
62
+ const resolved = resolveAutocompleteLookup(payload, value, cursor);
63
+ assert.ok(resolved);
64
+ assert.strictEqual(resolved.lookupPrefix, 'account_id.');
65
+ const fields = getSourceFieldsAtPath(payload, resolved.lookupPrefix);
66
+ assert.ok(fields.some((field: any) => field.key === 'last_name'));
67
+ assert.ok(fields.some((field: any) => field.key === 'billing_address'));
68
+ });
69
+
70
+ it('resolveAutocompleteLookup also works for mistaken $account_id.', () => {
71
+ const payload = { account_id: { last_name: 'Ada' }, name: 'Opp' };
72
+ const value = '"Customer": "$account_id."';
73
+ const cursor = value.indexOf('$account_id.') + '$account_id.'.length;
74
+ const resolved = resolveAutocompleteLookup(payload, value, cursor);
75
+ assert.ok(resolved);
76
+ assert.strictEqual(resolved.lookupPrefix, 'account_id.');
77
+ const fields = getSourceFieldsAtPath(payload, resolved.lookupPrefix);
78
+ assert.ok(fields.some((field: any) => field.key === 'last_name'));
38
79
  });
39
80
 
40
81
  it('insertPathSegmentAtCursor completes only the current segment', () => {
41
82
  const textarea = patchTextarea(document.createElement('textarea'));
42
83
  textarea.dispatchEvent = () => true;
43
- textarea.value = '"city": "$payload.sections.he';
84
+ textarea.value = '"city": "sections.he';
44
85
  textarea.selectionStart = textarea.value.length;
45
86
  textarea.selectionEnd = textarea.value.length;
46
87
 
47
88
  insertPathSegmentAtCursor(textarea, {
48
89
  key: 'header',
49
- path: '$payload.sections.header',
90
+ path: 'sections.header',
50
91
  type: 'object',
51
92
  });
52
93
 
53
- assert.strictEqual(textarea.value, '"city": "$payload.sections.header');
94
+ assert.strictEqual(textarea.value, '"city": "sections.header');
54
95
  });
55
96
 
56
97
  it('resolveAutocompleteLookup drills into completed object segment without trailing dot', () => {
@@ -60,12 +101,12 @@ describe('mapping-result-helper', () => {
60
101
  items: { Table: [{ name: 'A', amount: '1' }] },
61
102
  },
62
103
  };
63
- const value = '"city": "$payload.sections.items.Table"';
104
+ const value = '"city": "sections.items.Table"';
64
105
  const cursor = value.length - 1;
65
106
 
66
107
  const resolved = resolveAutocompleteLookup(payload, value, cursor);
67
108
  assert.ok(resolved);
68
- assert.strictEqual(resolved.lookupPrefix, '$payload.sections.items.Table.');
109
+ assert.strictEqual(resolved.lookupPrefix, 'sections.items.Table.');
69
110
 
70
111
  const fields = getSourceFieldsAtPath(payload, resolved.lookupPrefix);
71
112
  assert.ok(fields.some((field: any) => field.key === 'name'));
@@ -74,22 +115,22 @@ describe('mapping-result-helper', () => {
74
115
 
75
116
  it('resolveAutocompleteLookup keeps partial segment for filtering', () => {
76
117
  const payload = { sections: { header: { Text: 'hello' } } };
77
- const value = '"city": "$payload.sections.he';
118
+ const value = '"city": "sections.he';
78
119
  const cursor = value.length;
79
120
 
80
121
  const resolved = resolveAutocompleteLookup(payload, value, cursor);
81
122
  assert.ok(resolved);
82
- assert.strictEqual(resolved.lookupPrefix, '$payload.sections.he');
123
+ assert.strictEqual(resolved.lookupPrefix, 'sections.he');
83
124
  });
84
125
 
85
126
  it('insertPathSegmentAtCursor replaces selected range', () => {
86
127
  const textarea = patchTextarea(document.createElement('textarea'));
87
- textarea.value = '"city": "$payload.old"';
128
+ textarea.value = '"city": "old"';
88
129
  textarea.selectionStart = 9;
89
- textarea.selectionEnd = 21;
130
+ textarea.selectionEnd = 12;
90
131
 
91
132
  const range = getPathInsertRange(textarea);
92
- assert.deepEqual(range, { start: 9, end: 21, prefix: '$payload.old' });
133
+ assert.deepEqual(range, { start: 9, end: 12, prefix: 'old' });
93
134
  });
94
135
 
95
136
  it('getMappingResultLeafKey prefers column and child path tails', () => {
@@ -108,7 +149,7 @@ describe('mapping-result-helper', () => {
108
149
  version: 1,
109
150
  sections: {
110
151
  Anamnesis: {
111
- Complaints: '$payload.sections.anamnesis.complaints',
152
+ Complaints: 'sections.anamnesis.complaints',
112
153
  },
113
154
  },
114
155
  },
@@ -118,12 +159,12 @@ describe('mapping-result-helper', () => {
118
159
  const range = findMappingResultSelection(text, {
119
160
  section: 'Anamnesis',
120
161
  field: 'Complaints',
121
- sourcePath: '$payload.sections.anamnesis.complaints',
162
+ sourcePath: 'sections.anamnesis.complaints',
122
163
  });
123
164
  assert.ok(range);
124
165
  assert.equal(
125
166
  text.slice(range.start, range.end),
126
- '"$payload.sections.anamnesis.complaints"',
167
+ '"sections.anamnesis.complaints"',
127
168
  );
128
169
  });
129
170
 
@@ -134,7 +175,7 @@ describe('mapping-result-helper', () => {
134
175
  version: 2,
135
176
  sections: {
136
177
  Anamnesis: {
137
- Complaints2: '$payload.sections.Untitled.Text_2',
178
+ Complaints2: 'sections.Untitled.Text_2',
138
179
  },
139
180
  },
140
181
  },
@@ -157,7 +198,7 @@ describe('mapping-result-helper', () => {
157
198
  version: 2,
158
199
  sections: {
159
200
  Anamnesis: {
160
- Complaints: '$payload.sections.Untitled.TT',
201
+ Complaints: 'sections.Untitled.TT',
161
202
  },
162
203
  },
163
204
  },
@@ -168,13 +209,13 @@ describe('mapping-result-helper', () => {
168
209
  {
169
210
  section: 'Anamnesis',
170
211
  field: 'Complaints',
171
- sourcePath: '$payload.sections.Untitled.TT',
212
+ sourcePath: 'sections.Untitled.TT',
172
213
  severity: 'warning',
173
- message: 'Source path "$payload.sections.Untitled.TT" does not exist in the payload.',
214
+ message: 'Source path "sections.Untitled.TT" does not exist in the payload.',
174
215
  },
175
216
  ]);
176
217
  assert.equal(ranges.length, 1);
177
- assert.equal(text.slice(ranges[0].start, ranges[0].end), '"$payload.sections.Untitled.TT"');
218
+ assert.equal(text.slice(ranges[0].start, ranges[0].end), '"sections.Untitled.TT"');
178
219
  });
179
220
 
180
221
  it('buildMappingResultHighlightHtml wraps issue ranges in mark tags', () => {
@@ -9,7 +9,10 @@ import {
9
9
  * @returns {{ start: number; end: number; prefix: string } | null}
10
10
  */
11
11
  export function findPathTokenAtCursor(value: any,cursor: any) {
12
- const re = /\$[\w.]+(?:\[[^\]]+\])*/g;
12
+ // Absolute bare paths (`close_date`, `account_id.`) or `$`-paths (`$qty`, legacy `$payload…`).
13
+ // Trailing `.` is included so typing `account_id.` still opens the field helper.
14
+ // Stop at JSON quotes / whitespace so `"old"` does not swallow the closing quote.
15
+ const re = /\$?[A-Za-z_][\w]*(?:\[[^\]]+\])?(?:\.[A-Za-z_][\w]*(?:\[[^\]]+\])?)*\.?/g;
13
16
  let match: any;
14
17
  while ((match = re.exec(value)) !== null) {
15
18
  const start = match.index;
@@ -21,6 +24,20 @@ export function findPathTokenAtCursor(value: any,cursor: any) {
21
24
  return null;
22
25
  }
23
26
 
27
+ /**
28
+ * Mapping-result autocomplete always lists against the root sample.
29
+ * Normalize legacy `$payload…` and mistaken `$account_id.` absolute typing to bare paths.
30
+ * @param {string} prefix
31
+ */
32
+ function normalizeAutocompleteLookupPrefix(prefix: any): string {
33
+ const text = String(prefix ?? '');
34
+ if (!text || text === '$payload' || text === '$payload.') return '';
35
+ if (text.startsWith('$payload.')) return text.slice('$payload.'.length);
36
+ // `$account_id.` → `account_id.` so root object children appear in the helper.
37
+ if (text.startsWith('$') && !text.startsWith('$payload')) return text.slice(1);
38
+ return text;
39
+ }
40
+
24
41
  /**
25
42
  * @param {unknown} payload
26
43
  * @param {string} value
@@ -29,22 +46,23 @@ export function findPathTokenAtCursor(value: any,cursor: any) {
29
46
  */
30
47
  export function resolveAutocompleteLookup(payload: any,value: any,cursor: any) {
31
48
  const token = findPathTokenAtCursor(value, cursor);
32
- if (!token?.prefix.startsWith('$')) return null;
49
+ if (!token?.prefix) return null;
33
50
 
34
51
  const context = parsePathTokenContext(token.prefix);
35
- if (!context) return { token, lookupPrefix: token.prefix };
52
+ if (!context) {
53
+ return { token, lookupPrefix: normalizeAutocompleteLookupPrefix(token.prefix) };
54
+ }
36
55
 
37
- let lookupPrefix = token.prefix;
38
- if (token.prefix.endsWith('.')) {
39
- return { token, lookupPrefix };
56
+ let lookupPrefix = normalizeAutocompleteLookupPrefix(token.prefix);
57
+ if (token.prefix.endsWith('.') || lookupPrefix.endsWith('.')) {
58
+ return { token, lookupPrefix: lookupPrefix.endsWith('.') ? lookupPrefix : `${lookupPrefix}.` };
40
59
  }
41
60
 
42
61
  const atTokenEnd = cursor >= token.end;
43
62
  if (atTokenEnd && context.segmentPrefix) {
44
- const parentLookup = context.basePath === '$payload'
45
- ? '$payload.'
46
- : `${context.basePath}.`;
47
- const siblings = getSourceFieldsAtPath(payload, parentLookup);
63
+ const bareBase = normalizeAutocompleteLookupPrefix(context.basePath);
64
+ const parentLookup = bareBase ? `${bareBase}.` : '';
65
+ const siblings = getSourceFieldsAtPath(payload, parentLookup || context.segmentPrefix);
48
66
  const match = siblings.find((field: any) => field.key === context.segmentPrefix);
49
67
  if (match && (match.type === 'object' || match.type === 'array')) {
50
68
  lookupPrefix = `${match.path}.`;
@@ -590,8 +608,8 @@ export function wireMappingResultPathHelper(textarea: any,_anchorEl: any) {
590
608
 
591
609
  if (!resolved && options.force) {
592
610
  resolved = {
593
- token: { start: cursor, end: cursor, prefix: '$payload' },
594
- lookupPrefix: '$payload.',
611
+ token: { start: cursor, end: cursor, prefix: '' },
612
+ lookupPrefix: '',
595
613
  };
596
614
  }
597
615
 
@@ -45,8 +45,8 @@ const SAMPLE = {
45
45
 
46
46
  describe('source-path-canvas-drop helpers', () => {
47
47
  it('sourcePathLeafKey extracts the last segment', () => {
48
- assert.equal(sourcePathLeafKey('$payload.records.name'), 'name');
49
- assert.equal(sourcePathLeafKey('$payload.records'), 'records');
48
+ assert.equal(sourcePathLeafKey('records.name'), 'name');
49
+ assert.equal(sourcePathLeafKey('records'), 'records');
50
50
  assert.equal(sourcePathLeafKey('$payload["Odd Key"]'), 'Odd Key');
51
51
  });
52
52
 
@@ -68,10 +68,10 @@ describe('source-path-canvas-drop helpers', () => {
68
68
  });
69
69
 
70
70
  it('detects array-member paths vs object/scalar paths', () => {
71
- assert.equal(isArrayMemberSourcePath('$payload.records.name', SAMPLE), true);
72
- assert.equal(isArrayMemberSourcePath('$payload.status', SAMPLE), false);
73
- assert.equal(isArrayMemberSourcePath('$payload.project.name', SAMPLE), false);
74
- assert.equal(isArrayMemberSourcePath('$payload.records', SAMPLE), false);
71
+ assert.equal(isArrayMemberSourcePath('records.name', SAMPLE), true);
72
+ assert.equal(isArrayMemberSourcePath('status', SAMPLE), false);
73
+ assert.equal(isArrayMemberSourcePath('project.name', SAMPLE), false);
74
+ assert.equal(isArrayMemberSourcePath('records', SAMPLE), false);
75
75
  });
76
76
 
77
77
  it('classifies nested values.amount as a table column (not a scalar field)', () => {
@@ -92,11 +92,11 @@ describe('source-path-canvas-drop helpers', () => {
92
92
  },
93
93
  };
94
94
  assert.equal(
95
- isArrayMemberSourcePath('$payload.sections.items.Table.values.amount', sample),
95
+ isArrayMemberSourcePath('sections.items.Table.values.amount', sample),
96
96
  true,
97
97
  );
98
98
  const plan = classifySourcePathDrop({
99
- path: '$payload.sections.items.Table.values.amount',
99
+ path: 'sections.items.Table.values.amount',
100
100
  type: 'string',
101
101
  sample,
102
102
  });
@@ -104,32 +104,32 @@ describe('source-path-canvas-drop helpers', () => {
104
104
  if (plan.kind !== 'table-column') return;
105
105
  assert.equal(plan.column.key, 'amount');
106
106
  assert.equal(plan.column.label, 'Amount');
107
- assert.equal(plan.sourceArrayPath, '$payload.sections.items.Table.values');
108
- assert.equal(plan.sourcePath, '$payload.sections.items.Table.values.amount');
107
+ assert.equal(plan.sourceArrayPath, 'sections.items.Table.values');
108
+ assert.equal(plan.sourcePath, 'sections.items.Table.values.amount');
109
109
  });
110
110
 
111
111
  it('classifies scalars as typed fields', () => {
112
112
  assert.deepEqual(
113
- classifySourcePathDrop({ path: '$payload.status', type: 'string', sample: SAMPLE }),
114
- { kind: 'field', label: 'Status', fieldType: 'text', sourcePath: '$payload.status' },
113
+ classifySourcePathDrop({ path: 'status', type: 'string', sample: SAMPLE }),
114
+ { kind: 'field', label: 'Status', fieldType: 'text', sourcePath: 'status' },
115
115
  );
116
116
  assert.deepEqual(
117
- classifySourcePathDrop({ path: '$payload.sort', type: 'number', sample: SAMPLE }),
118
- { kind: 'field', label: 'Sort', fieldType: 'number', sourcePath: '$payload.sort' },
117
+ classifySourcePathDrop({ path: 'sort', type: 'number', sample: SAMPLE }),
118
+ { kind: 'field', label: 'Sort', fieldType: 'number', sourcePath: 'sort' },
119
119
  );
120
120
  assert.deepEqual(
121
- classifySourcePathDrop({ path: '$payload.inactive', type: 'boolean', sample: SAMPLE }),
122
- { kind: 'field', label: 'Inactive', fieldType: 'logical', sourcePath: '$payload.inactive' },
121
+ classifySourcePathDrop({ path: 'inactive', type: 'boolean', sample: SAMPLE }),
122
+ { kind: 'field', label: 'Inactive', fieldType: 'logical', sourcePath: 'inactive' },
123
123
  );
124
124
  assert.deepEqual(
125
- classifySourcePathDrop({ path: '$payload.project.name', type: 'string', sample: SAMPLE }),
126
- { kind: 'field', label: 'Name', fieldType: 'text', sourcePath: '$payload.project.name' },
125
+ classifySourcePathDrop({ path: 'project.name', type: 'string', sample: SAMPLE }),
126
+ { kind: 'field', label: 'Name', fieldType: 'text', sourcePath: 'project.name' },
127
127
  );
128
128
  });
129
129
 
130
130
  it('classifies array members as table columns', () => {
131
131
  const plan = classifySourcePathDrop({
132
- path: '$payload.records.name',
132
+ path: 'records.name',
133
133
  type: 'string',
134
134
  sample: SAMPLE,
135
135
  });
@@ -137,13 +137,13 @@ describe('source-path-canvas-drop helpers', () => {
137
137
  if (plan.kind !== 'table-column') return;
138
138
  assert.equal(plan.column.key, 'name');
139
139
  assert.equal(plan.column.label, 'Name');
140
- assert.equal(plan.sourcePath, '$payload.records.name');
141
- assert.equal(plan.sourceArrayPath, '$payload.records');
140
+ assert.equal(plan.sourcePath, 'records.name');
141
+ assert.equal(plan.sourceArrayPath, 'records');
142
142
  });
143
143
 
144
144
  it('uses humanized field labels for table columns', () => {
145
145
  const plan = classifySourcePathDrop({
146
- path: '$payload.records.date_visit_start',
146
+ path: 'records.date_visit_start',
147
147
  type: 'string',
148
148
  sample: {
149
149
  records: [{ date_visit_start: '2026-10-05T09:00:00+02:00' }],
@@ -158,7 +158,7 @@ describe('source-path-canvas-drop helpers', () => {
158
158
 
159
159
  it('prefers explicit drag label for table columns', () => {
160
160
  const plan = classifySourcePathDrop({
161
- path: '$payload.records.date_visit_start',
161
+ path: 'records.date_visit_start',
162
162
  type: 'string',
163
163
  label: 'Date Visit Start',
164
164
  sample: {
@@ -172,7 +172,7 @@ describe('source-path-canvas-drop helpers', () => {
172
172
 
173
173
  it('classifies array-of-objects as multi-column table', () => {
174
174
  const plan = classifySourcePathDrop({
175
- path: '$payload.records',
175
+ path: 'records',
176
176
  type: 'array',
177
177
  sample: SAMPLE,
178
178
  });
@@ -185,7 +185,7 @@ describe('source-path-canvas-drop helpers', () => {
185
185
 
186
186
  it('builds mapping rules with sourceArrayPath for table columns', () => {
187
187
  const plan = classifySourcePathDrop({
188
- path: '$payload.records.name',
188
+ path: 'records.name',
189
189
  type: 'string',
190
190
  sample: SAMPLE,
191
191
  });
@@ -218,8 +218,8 @@ describe('source-path-canvas-drop helpers', () => {
218
218
  });
219
219
  assert.equal(rules.length, 1);
220
220
  assert.equal(rules[0].columnKey, 'name');
221
- assert.equal(rules[0].sourcePath, '$payload.records.name');
222
- assert.equal(rules[0].sourceArrayPath, '$payload.records');
221
+ assert.equal(rules[0].sourcePath, 'records.name');
222
+ assert.equal(rules[0].sourceArrayPath, 'records');
223
223
  });
224
224
 
225
225
  it('findTableIdForSourceArrayPath locates an existing mapped table', () => {
@@ -228,14 +228,14 @@ describe('source-path-canvas-drop helpers', () => {
228
228
  {
229
229
  fieldId: 'tbl1',
230
230
  columnKey: 'name',
231
- sourceArrayPath: '$payload.records',
232
- sourcePath: '$payload.records.name',
231
+ sourceArrayPath: 'records',
232
+ sourcePath: 'records.name',
233
233
  },
234
234
  ],
235
- '$payload.records',
235
+ 'records',
236
236
  );
237
237
  assert.equal(id, 'tbl1');
238
- assert.equal(findTableIdForSourceArrayPath([], '$payload.records'), null);
238
+ assert.equal(findTableIdForSourceArrayPath([], 'records'), null);
239
239
  });
240
240
 
241
241
  it('mergeMappingRulesIntoSpec upserts rules and preserves sourceSample', () => {
@@ -246,7 +246,7 @@ describe('source-path-canvas-drop helpers', () => {
246
246
  section: 'main',
247
247
  field: 'status',
248
248
  fieldId: 'main_status',
249
- sourcePath: '$payload.status',
249
+ sourcePath: 'status',
250
250
  },
251
251
  ],
252
252
  );
@@ -35,6 +35,9 @@ function readSampleAtPath(sample: any, path: string) {
35
35
  rel = rel.slice('$payload.'.length);
36
36
  } else if (rel === '$payload') {
37
37
  return sample;
38
+ } else if (rel.startsWith('$') && !rel.startsWith('$payload')) {
39
+ // Relative `$field` — sample tree only holds absolute paths.
40
+ rel = rel.slice(1);
38
41
  }
39
42
  if (!rel) return sample;
40
43