mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
* add visual feedback for invalid value
* add focal point MVP
* Revert "add visual feedback for invalid value"
This reverts commit 1df1868342.
Accidently committed some local testing stuff. Pls disregard! :)
* fix wrong cropping
* fix text for new cropping, import correct type
* fix saving
* place initial focal point to saved value or center, display different cancel text
* split up tooltips
* honor rotations & flips when saving focal point
* apply custom cropper styles for focal mode
* Create loud-crews-fix.md
* add test and only crop when covering with fixed dimensions to preserve default behaviour
* linter gods pls forgive me
* replace json field with two int fields
* add focal point to sdk
* fix transformation for the two new db columns
* update test for new columns, add new tests
* wip: saving now differentiates between only img data and focal point and only enable saving if there are changes
but this is not optimal. would be better to check beforehand if we can collapse
to requests to one. Now its bad because
one request might succeed and the other fails.
* refactor image editor change persistence
now we save it in one request!
* Update loud-crews-fix.md
* add `focal_point_x` and `focal_point_y` to possible asset transformations
* fix assigning localdragmode upon cropper init
* reuse fetched fields in type
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
* update file type
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
* update changeset
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
* improve type for `ASSET_TRANSFORM_QUERY_KEYS`
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
* Apply suggestions from code review
Trying out the batch change feature from github for the first time. Lets see.
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
* rename `persistChanges` to `saveImage`
* Add docs for focal points (#20959)
* Add user guide
* Added to API Reference
* Prettier
* Spellchecker
* default null
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
* from -> around
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
* from -> around
---------
Co-authored-by: Daniel Biegler <DanielBiegler@users.noreply.github.com>
* add changeset for docs
* run prettier lets goooooooo
* move & show focal point fields and add divider
---------
Co-authored-by: Brainslug <br41nslug@users.noreply.github.com>
Co-authored-by: Pascal Jufer <pascal-jufer@bluewin.ch>
Co-authored-by: Kevin Lewis <kvn@lws.io>
Directus JavaScript SDK
Features
- TypeScript first: The SDK provides a robust and type-safe development experience.
- Modular architecture: The SDK is split into separate modules, giving you granular control over which features to include and which can be pruned at build-time.
- Lightweight and dependency-free: It does not require external libraries, ensuring a lighter bundle and streamlined experience.
Composable Client
The client is split up in separate features you can mix and match to compose a client with only the features you need or want.
const client = createDirectus<Schema>('https://api.directus.io');
This client is currently an empty wrapper without any functionality. Before you can do anything with it you'll need to add some features. The following composables are available/in progress:
rest()REST request functions- adds
.request(...)on the client
- adds
graphql()GraphQL request functions- adds
.query(...)on the client
- adds
staticToken()authentication functions- adds
.getToken()and.setToken()on the client
- adds
authenticate()authentication functions- adds
.login({ email, password }),.logout(),.refresh()on the client - adds
.getToken()and.setToken()on the client
- adds
realtime()websocket connectivity- adds
.subscribe(...),.sendMessage(...),.onWebsocket('message', (message) => {})on the client
- adds
For this example we'll build a client including rest and graphql:
const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(graphql());
// do a REST request
const restResult = await client.request(readItems('articles'));
// do a GraphQL request
const gqlResult = await client.query<OutputType>(`
query {
articles {
id
title
author {
first_name
}
}
}
`);
Authentication
const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(authentication('json'));
await client.login('admin@example.com', 'd1r3ctu5');
// do authenticated requests
const client = createDirectus<Schema>('https://api.directus.io').with(rest()).with(staticToken('super-secure-token'));
// do authenticated requests
Real-Time
The realtime() extension allows you to work with a Directus REST WebSocket.
Subscribing to updates:
const client = createDirectus<Schema>('https://api.directus.io').with(
realtime({
authMode: 'public',
}),
);
const { subscription, unsubscribe } = await client.subscribe('test', {
query: { fields: ['*'] },
});
for await (const item of subscription) {
console.log('subscription', { item });
}
// unsubscribe()
Receive/Send messages:
const client = createDirectus<Schema>('https://api.directus.io').with(
realtime({
authMode: 'public',
}),
);
const stop = client.onWebSocket('message', (message) => {
if ('type' in message && message['type'] === 'pong') {
console.log('PONG received');
stop();
}
});
client.sendMessage({ type: 'ping' });
Build Your Schema
// The main schema type containing all collections available
interface MySchema {
collection_a: CollectionA[]; // regular collections are array types
collection_b: CollectionB[];
collection_c: CollectionC; // this is a singleton
// junction collections are collections too
collection_a_b_m2m: CollectionAB_Many[];
collection_a_b_m2a: CollectionAB_Any[];
}
// collection A
interface CollectionA {
id: number;
status: string;
// relations
m2o: number | CollectionB;
o2m: number[] | CollectionB[];
m2m: number[] | CollectionAB_Many[];
m2a: number[] | CollectionAB_Any[];
}
// Many-to-Many junction table
interface CollectionAB_Many {
id: number;
collection_a_id: CollectionA;
collection_b_id: CollectionB;
}
// Many-to-Any junction table
interface CollectionAB_Any {
id: number;
collection_a_id: CollectionA;
collection: 'collection_b' | 'collection_c';
item: string | CollectionB | CollectionC;
}
// collection B
interface CollectionB {
id: number;
value: string;
}
// singleton collection
interface CollectionC {
id: number;
app_settings: string;
something: string;
}