Skip to content

Commit 0b9052a

Browse files
committed
feat(PrismCode): react renderer * 13
1 parent 73c34d8 commit 0b9052a

File tree

13 files changed

+149
-53
lines changed

13 files changed

+149
-53
lines changed

.size-limit.cjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ module.exports = [
2020
}),
2121
);
2222
},
23-
limit: '251kB',
23+
limit: '258kB',
2424
},
2525
{
2626
name: 'Tree shaking (just a Button)',

src/_internal/hooks/use-event.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable @typescript-eslint/no-explicit-any */
21
import { useCallback } from 'react';
32

43
import { useSyncRef } from './use-sync-ref';

src/_internal/hooks/use-update-effect.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,5 @@ export function useUpdateEffect(effect: EffectCallback, deps?: DependencyList) {
99
if (!isFirst) {
1010
return effect();
1111
}
12-
// eslint-disable-next-line react-hooks/exhaustive-deps
1312
}, deps);
1413
}

src/components/content/PrismCode/PrismCode.stories.tsx

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -12,24 +12,29 @@ export default {
1212
},
1313
};
1414

15-
const Template = ({ ...args }) => <PrismCode {...args} />;
15+
const Template = (args: any) => <PrismCode {...args} />;
1616

17-
export const OneLine = Template.bind({});
18-
OneLine.args = {
19-
language: 'bash',
20-
code: '$ npm install -g cubejs-cli',
17+
export const OneLine = {
18+
render: Template,
19+
args: {
20+
language: 'bash',
21+
code: '$ npm install -g cubejs-cli',
22+
},
2123
};
2224

23-
export const MultiLine = Template.bind({});
24-
MultiLine.args = {
25-
language: 'bash',
26-
code: '$ npm install -g cubejs-cli\n$ cubejs deploy',
25+
export const MultiLine = {
26+
render: Template,
27+
args: {
28+
language: 'bash',
29+
code: '$ npm install -g cubejs-cli\n$ cubejs deploy',
30+
},
2731
};
2832

29-
export const JavascriptSyntax = Template.bind({});
30-
JavascriptSyntax.args = {
31-
language: 'javascript',
32-
code: `cube('LineItems', {
33+
export const JavascriptSyntax = {
34+
render: Template,
35+
args: {
36+
language: 'javascript',
37+
code: `cube('LineItems', {
3338
sql: \`SELECT * FROM public.line_items\`,
3439
3540
@@ -75,12 +80,14 @@ JavascriptSyntax.args = {
7580
}
7681
}
7782
});`,
83+
},
7884
};
7985

80-
export const YamlSyntax = Template.bind({});
81-
YamlSyntax.args = {
82-
language: 'yaml',
83-
code: `cubes:
86+
export const YamlSyntax = {
87+
render: Template,
88+
args: {
89+
language: 'yaml',
90+
code: `cubes:
8491
# Define the Orders cube
8592
- name: Orders
8693
sql: SELECT * FROM public.orders
@@ -138,12 +145,14 @@ YamlSyntax.args = {
138145
- cube: Orders
139146
sql: \${Customers.id} = \${Orders.customer_id}
140147
relationship: one_to_many # One customer can have many orders`,
148+
},
141149
};
142150

143-
export const SqlSyntax = Template.bind({});
144-
SqlSyntax.args = {
145-
language: 'sql',
146-
code: `WITH RecursiveCTE AS (
151+
export const SqlSyntax = {
152+
render: Template,
153+
args: {
154+
language: 'sql',
155+
code: `WITH RecursiveCTE AS (
147156
-- Recursive CTE to generate a sequence of numbers
148157
SELECT 1 AS Level, CAST('2025-01-01' AS DATE) AS GeneratedDate
149158
UNION ALL
@@ -196,13 +205,16 @@ SELECT
196205
fo.GeneratedDate
197206
FROM FinalOutput fo
198207
ORDER BY fo.GeneratedDate, fo.UserID;`,
208+
},
199209
};
200210

201-
export const DiffSyntax = Template.bind({});
202-
DiffSyntax.args = {
203-
language: 'javascript',
204-
code: ` console.log('Hello, world!');
211+
export const DiffSyntax = {
212+
render: Template,
213+
args: {
214+
language: 'javascript',
215+
code: ` console.log('Hello, world!');
205216
+ console.log('This line was added!');
206217
console.log('Another unchanged line');
207218
- console.log('This line was removed.');`,
219+
},
208220
};

src/components/content/PrismCode/__tests__/diffHighlight.test.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,44 @@ describe('Prism diff-highlight plugin', () => {
221221

222222
expect(hasNestedSql).toBe(true);
223223
});
224+
225+
test('YAML grammar supports SQL highlighting in sql fields', () => {
226+
const yamlCode = `cubes:
227+
- name: orders
228+
sql: SELECT id, name FROM orders WHERE active = 1
229+
measures:
230+
- name: count
231+
sql: COUNT(*)`;
232+
233+
const tokens = Prism.tokenize(yamlCode, Prism.languages.yaml, 'yaml');
234+
235+
// Check if SQL tokens are present
236+
const hasKeywords = JSON.stringify(tokens).includes('"keyword"');
237+
const hasSqlKeywords =
238+
JSON.stringify(tokens).includes('SELECT') ||
239+
JSON.stringify(tokens).includes('COUNT');
240+
241+
expect(hasKeywords).toBe(true);
242+
expect(hasSqlKeywords).toBe(true);
243+
});
244+
245+
test('YAML grammar supports SQL highlighting in multiline folded blocks', () => {
246+
const yamlCode = `cubes:
247+
- name: orders
248+
sql: >
249+
SELECT 1 as id, 100 as amount, 'new' status
250+
UNION ALL
251+
SELECT 2 as id, 200 as amount, 'new' status`;
252+
253+
const tokens = Prism.tokenize(yamlCode, Prism.languages.yaml, 'yaml');
254+
255+
// Check if SQL tokens are present in the multiline block
256+
const hasKeywords = JSON.stringify(tokens).includes('"keyword"');
257+
const hasSqlKeywords =
258+
JSON.stringify(tokens).includes('SELECT') ||
259+
JSON.stringify(tokens).includes('UNION');
260+
261+
expect(hasKeywords).toBe(true);
262+
expect(hasSqlKeywords).toBe(true);
263+
});
224264
});

src/components/content/PrismCode/prismSetup.tsx

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,4 +219,48 @@ RendererPrism.languages.sql = {
219219
});
220220
})(RendererPrism);
221221

222+
// Extend YAML to support SQL syntax highlighting in sql: fields
223+
(function (Prism) {
224+
if (Prism.languages.yaml && Prism.languages.sql) {
225+
// Insert SQL patterns before existing YAML patterns for higher priority
226+
Prism.languages.insertBefore('yaml', 'key', {
227+
'sql-inline': {
228+
pattern: /((?:^|\n)\s*sql\s*:\s*)([^\n\r|>]+)/,
229+
lookbehind: true,
230+
inside: Prism.languages.sql,
231+
},
232+
});
233+
234+
// Handle multiline SQL blocks with proper indentation
235+
Prism.languages.insertBefore('yaml', 'key', {
236+
'sql-multiline': {
237+
pattern:
238+
/((?:^|\n)\s*sql\s*:\s*[|>][-+]?\s*\n)((?:\s{2,}[^\n\r]+(?:\n|$))+)/,
239+
lookbehind: true,
240+
inside: {
241+
'sql-content': {
242+
pattern: /^(\s+)(.+)/gm,
243+
inside: {
244+
indent: /^\s+/,
245+
'sql-code': {
246+
pattern: /.+/,
247+
inside: Prism.languages.sql,
248+
},
249+
},
250+
},
251+
},
252+
},
253+
});
254+
255+
// Handle YAML scalar content that follows sql: > or sql: | indicators
256+
Prism.languages.insertBefore('yaml', 'scalar', {
257+
'sql-scalar': {
258+
pattern:
259+
/^\s*(SELECT|INSERT|UPDATE|DELETE|WITH|CREATE|DROP|ALTER|UNION|FROM|WHERE|JOIN|GROUP|ORDER|HAVING)[\s\S]*$/im,
260+
inside: Prism.languages.sql,
261+
},
262+
});
263+
}
264+
})(RendererPrism);
265+
222266
export { RendererPrism as Prism };

src/components/content/PrismDiffCode/PrismDiffCode.stories.tsx

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import { baseProps } from '../../../stories/lists/baseProps';
22

33
import { PrismDiffCode } from './PrismDiffCode';
44

5+
import type { CubePrismDiffCodeProps } from './PrismDiffCode';
6+
57
export default {
68
title: 'Content/PrismDiffCode',
79
component: PrismDiffCode,
@@ -12,18 +14,19 @@ export default {
1214
},
1315
};
1416

15-
const Template = ({ ...args }) => <PrismDiffCode {...args} />;
17+
const Template = (args: CubePrismDiffCodeProps) => <PrismDiffCode {...args} />;
1618

1719
// export const JavascriptSyntax = Template.bind({});
1820
// JavascriptSyntax.args = {
1921
// language: 'javascript',
2022
// code: ``,
2123
// };
2224

23-
export const YamlSyntax = Template.bind({});
24-
YamlSyntax.args = {
25-
language: 'yaml',
26-
original: `cubes:
25+
export const YamlSyntax = {
26+
render: Template,
27+
args: {
28+
language: 'yaml',
29+
original: `cubes:
2730
# Define the Orders cube
2831
- name: Orders
2932
sql: SELECT * FROM public.orders
@@ -81,7 +84,7 @@ YamlSyntax.args = {
8184
- cube: Orders
8285
sql: \${Customers.id} = \${Orders.customer_id}
8386
relationship: one_to_many # One customer can have many orders`,
84-
modified: `cubes:
87+
modified: `cubes:
8588
# Define the Orders cube
8689
- name: Orders
8790
sql: SELECT * FROM public.orders
@@ -144,12 +147,14 @@ YamlSyntax.args = {
144147
- cube: Orders
145148
sql: \${Customers.id} = \${Orders.customer_id}
146149
relationship: one_to_many # One customer can have multiple orders`,
150+
},
147151
};
148152

149-
export const SqlSyntax = Template.bind({});
150-
SqlSyntax.args = {
151-
language: 'sql',
152-
original: `WITH RecursiveCTE AS (
153+
export const SqlSyntax = {
154+
render: Template,
155+
args: {
156+
language: 'sql',
157+
original: `WITH RecursiveCTE AS (
153158
-- Recursive CTE to generate a sequence of numbers
154159
SELECT 1 AS Level, CAST('2025-01-01' AS DATE) AS GeneratedDate
155160
UNION ALL
@@ -202,7 +207,7 @@ SELECT
202207
fo.GeneratedDate
203208
FROM FinalOutput fo
204209
ORDER BY fo.GeneratedDate, fo.UserID;`,
205-
modified: `WITH RecursiveDates AS (
210+
modified: `WITH RecursiveDates AS (
206211
-- Generate a sequence of dates starting from 2025-01-01
207212
SELECT 1 AS DayNumber, CAST('2025-01-01' AS DATE) AS GeneratedDate
208213
UNION ALL
@@ -253,13 +258,16 @@ SELECT
253258
fo.GeneratedDate
254259
FROM FinalOutput fo
255260
ORDER BY fo.GeneratedDate, fo.UserID;`,
261+
},
256262
};
257263

258-
export const EmptyLineDiff = Template.bind({});
259-
EmptyLineDiff.args = {
260-
modified:
261-
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n type: number\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
262-
original:
263-
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
264-
language: 'yaml',
264+
export const EmptyLineDiff = {
265+
render: Template,
266+
args: {
267+
modified:
268+
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n type: number\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
269+
original:
270+
"cubes:\n - name: orders\n sql: >\n select 1 as id, 100 as amount, 'new' status\n UNION ALL\n select 2 as id, 200 as amount, 'new' status\n UNION ALL\n select 3 as id, 300 as amount, 'processed' status\n UNION ALL\n select 4 as id, 500 as amount, 'processed' status\n UNION ALL\n select 5 as id, 600 as amount, 'shipped' status\n\n joins: []\n\n dimensions:\n - name: id\n\n - name: status\n sql: status\n\n\n measures:\n - name: count\n type: count\n\n - name: amount\n sql: amount\n type: sum\n\n pre_aggregations:\n # Pre-aggregation definitions go here.\n # Learn more in the documentation: https://cube.dev/docs/caching/pre-aggregations/getting-started\n\n",
271+
language: 'yaml',
272+
},
265273
};

src/components/overlays/NewNotifications/Notification.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export type NotificationProps = {
1212
*
1313
* @default false
1414
*/
15-
// eslint-disable-next-line react/boolean-prop-naming
15+
1616
disableRemoveOnUnmount?: boolean;
1717
} & CubeNotifyApiProps;
1818

@@ -35,7 +35,6 @@ export function Notification(props: NotificationProps) {
3535
useEffect(() => {
3636
notify({ id, ...props });
3737
// We can safety ignore props, bc we update notification in the another effect, this effect only mounts a notification.
38-
// eslint-disable-next-line react-hooks/exhaustive-deps
3938
}, [id]);
4039
useEffect(() => () => removeNotification(id), [id, removeNotification]);
4140
useEffect(() => update(id, props));

src/tasty/utils/dotize.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
/* eslint-disable */
21
// @ts-nocheck
32
// Convert complex js object to dot notation js object
43
// url: https://github.com/vardars/dotize

src/tasty/utils/styles.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ describe('applyStates', () => {
1010
function checkAppliance(list) {
1111
list.forEach((obj, i) => {
1212
it(`to list ${i}`, () => {
13-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
1413
// @ts-ignore
1514
expect(applyStates(...obj.input)).toEqual(obj.output);
1615
});

0 commit comments

Comments
 (0)