Skip to content

Commit

Permalink
feat: update selector
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Jul 22, 2024
1 parent 9bfa696 commit ac5a11e
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 14 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
],
"dependencies": {
"@antv/g6": "4.8.24",
"@gkd-kit/selector": "0.3.3",
"@gkd-kit/selector": "0.4.1",
"@gkd-kit/wasm_matches": "0.0.1",
"@rushstack/eslint-patch": "1.10.3",
"@tsconfig/node20": "20.1.4",
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

27 changes: 19 additions & 8 deletions src/utils/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ import {
UnknownMemberException,
UnknownMemberMethodException,
Context,
MatchOption,
FastQuery,
} from '@gkd-kit/selector';
import type { RawNode } from './types';
import matchesInstantiate from '@gkd-kit/wasm_matches';
Expand Down Expand Up @@ -64,6 +66,9 @@ const transform = Transform.Companion.multiplatformBuild<RawNode>(
if (name === 'prev') {
return target.prev;
}
if (name === 'current') {
return target.current;
}
return getNodeAttr(target.current, name);
}
if (isRawNode(target)) {
Expand Down Expand Up @@ -118,7 +123,8 @@ export type GkdSelector = {

export type ConnectKeyType = '+' | '-' | '>' | '<' | '<<';

const typeInfo = initDefaultTypeInfo();
const typeInfo = initDefaultTypeInfo(true).globalType;
const matchOption = new MatchOption(false, false);

export const parseSelector = (source: string): GkdSelector => {
const s = Selector.Companion.parse(source);
Expand All @@ -134,17 +140,22 @@ export const parseSelector = (source: string): GkdSelector => {
const selector: GkdSelector = {
s,
targetIndex: s.targetIndex,
connectKeys: s.connectKeys,
canQf: s.quickFindValue.canQf,
qfIdValue: s.quickFindValue.id,
qfVidValue: s.quickFindValue.vid,
qfTextValue: s.quickFindValue.text,
connectKeys: s.connectWrappers.map((c) => c.segment.operator.key),
canQf: !!s.quickFindValue?.value,
qfIdValue:
s.quickFindValue instanceof FastQuery.Id ? s.quickFindValue.value : null,
qfVidValue:
s.quickFindValue instanceof FastQuery.Vid ? s.quickFindValue.value : null,
qfTextValue:
s.quickFindValue instanceof FastQuery.Text
? s.quickFindValue.value
: null,
canCopy: !s.binaryExpressions.some((b) =>
b.properties.some((p) => p.startsWith('_')),
),
toString: () => s.stringify(),
match: (node) => {
return s.match(node, transform) ?? undefined;
return s.match(node, transform, matchOption) ?? undefined;
},
querySelectorAll: (node) => {
return transform.querySelectorAllArray(node, s);
Expand All @@ -163,7 +174,7 @@ export const checkSelector = (source: string) => {
};

const checkError = (s: Selector) => {
const error = s.checkType(typeInfo.contextType);
const error = s.checkType(typeInfo);
if (error != null) {
if (error instanceof MismatchExpressionTypeException) {
throw new Error('不匹配表达式类型:' + error.exception.stringify(), {
Expand Down

0 comments on commit ac5a11e

Please sign in to comment.