mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-03 10:40:44 +08:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 914e4baf82 | |||
| bd268044b4 |
@@ -6,7 +6,6 @@ yarn install
|
|||||||
|
|
||||||
# Build Server Dependencies
|
# Build Server Dependencies
|
||||||
yarn affine @affine/server-native build
|
yarn affine @affine/server-native build
|
||||||
yarn affine @affine/reader build
|
|
||||||
|
|
||||||
# Create database
|
# Create database
|
||||||
yarn affine @affine/server prisma migrate reset -f
|
yarn affine @affine/server prisma migrate reset -f
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
DATABASE_URL: postgresql://affine:affine@db:5432/affine
|
DATABASE_URL: postgresql://affine:affine@db:5432/affine
|
||||||
REDIS_SERVER_HOST: redis
|
REDIS_SERVER_HOST: redis
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT: http://indexer:9308
|
|
||||||
|
|
||||||
db:
|
db:
|
||||||
image: pgvector/pgvector:pg16
|
image: pgvector/pgvector:pg16
|
||||||
@@ -24,19 +23,5 @@ services:
|
|||||||
redis:
|
redis:
|
||||||
image: redis
|
image: redis
|
||||||
|
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:${MANTICORE_VERSION:-9.3.2}
|
|
||||||
ulimits:
|
|
||||||
nproc: 65535
|
|
||||||
nofile:
|
|
||||||
soft: 65535
|
|
||||||
hard: 65535
|
|
||||||
memlock:
|
|
||||||
soft: -1
|
|
||||||
hard: -1
|
|
||||||
volumes:
|
|
||||||
- manticoresearch_data:/var/lib/manticore
|
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres-data:
|
postgres-data:
|
||||||
manticoresearch_data:
|
|
||||||
|
|||||||
@@ -3,13 +3,4 @@ DB_VERSION=16
|
|||||||
# database credentials
|
# database credentials
|
||||||
DB_PASSWORD=affine
|
DB_PASSWORD=affine
|
||||||
DB_USERNAME=affine
|
DB_USERNAME=affine
|
||||||
DB_DATABASE_NAME=affine
|
DB_DATABASE_NAME=affine
|
||||||
|
|
||||||
# elasticsearch env
|
|
||||||
# ELASTIC_VERSION=9.0.1
|
|
||||||
# enable for arm64, e.g.: macOS M1+
|
|
||||||
# ELASTIC_VERSION_ARM64=-arm64
|
|
||||||
# ELASTIC_PLATFORM=linux/arm64
|
|
||||||
|
|
||||||
# manticoresearch
|
|
||||||
MANTICORE_VERSION=9.3.2
|
|
||||||
@@ -1,6 +1,3 @@
|
|||||||
postgres
|
postgres
|
||||||
.env
|
.env
|
||||||
compose.yml
|
compose.yml
|
||||||
certs/*
|
|
||||||
!certs/.gitkeep
|
|
||||||
nginx/conf.d/*
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
# Dev containers
|
|
||||||
|
|
||||||
## Develop with domain
|
|
||||||
|
|
||||||
> MacOs only, OrbStack only
|
|
||||||
|
|
||||||
### 1. Generate and install Root CA
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# the root ca file will be located at `./.docker/dev/certs/ca`
|
|
||||||
yarn affine cert --install
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. Generate domain certs
|
|
||||||
|
|
||||||
```bash
|
|
||||||
# certificates will be located at `./.docker/dev/certs/${domain}`
|
|
||||||
yarn affine cert --domain dev.affine.fail
|
|
||||||
```
|
|
||||||
|
|
||||||
### 3. Enable dns and nginx service in compose.yml
|
|
||||||
|
|
||||||
### 4. Add custom dns server
|
|
||||||
|
|
||||||
```bash
|
|
||||||
echo "nameserver 127.0.0.1" | sudo tee /etc/resolver/dev.affine.fail
|
|
||||||
```
|
|
||||||
@@ -24,78 +24,8 @@ services:
|
|||||||
- 1025:1025
|
- 1025:1025
|
||||||
- 8025:8025
|
- 8025:8025
|
||||||
|
|
||||||
# https://manual.manticoresearch.com/Starting_the_server/Docker
|
|
||||||
manticoresearch:
|
|
||||||
image: manticoresearch/manticore:${MANTICORE_VERSION:-9.3.2}
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
ulimits:
|
|
||||||
nproc: 65535
|
|
||||||
nofile:
|
|
||||||
soft: 65535
|
|
||||||
hard: 65535
|
|
||||||
memlock:
|
|
||||||
soft: -1
|
|
||||||
hard: -1
|
|
||||||
volumes:
|
|
||||||
- manticoresearch_data:/var/lib/manticore
|
|
||||||
|
|
||||||
# elasticsearch:
|
|
||||||
# image: docker.elastic.co/elasticsearch/elasticsearch:${ELASTIC_VERSION:-9.0.1}${ELASTIC_VERSION_ARM64}
|
|
||||||
# platform: ${ELASTIC_PLATFORM}
|
|
||||||
# labels:
|
|
||||||
# co.elastic.logs/module: elasticsearch
|
|
||||||
# volumes:
|
|
||||||
# - elasticsearch_data:/usr/share/elasticsearch/data
|
|
||||||
# ports:
|
|
||||||
# - ${ES_PORT:-9200}:9200
|
|
||||||
# environment:
|
|
||||||
# - node.name=es01
|
|
||||||
# - cluster.name=affine-dev
|
|
||||||
# - discovery.type=single-node
|
|
||||||
# - bootstrap.memory_lock=true
|
|
||||||
# - xpack.security.enabled=false
|
|
||||||
# - xpack.security.http.ssl.enabled=false
|
|
||||||
# - xpack.security.transport.ssl.enabled=false
|
|
||||||
# - xpack.license.self_generated.type=basic
|
|
||||||
# mem_limit: ${ES_MEM_LIMIT:-1073741824}
|
|
||||||
# ulimits:
|
|
||||||
# memlock:
|
|
||||||
# soft: -1
|
|
||||||
# hard: -1
|
|
||||||
# healthcheck:
|
|
||||||
# test:
|
|
||||||
# [
|
|
||||||
# "CMD-SHELL",
|
|
||||||
# "curl -s http://localhost:9200 | grep -q 'affine-dev'",
|
|
||||||
# ]
|
|
||||||
# interval: 10s
|
|
||||||
# timeout: 10s
|
|
||||||
# retries: 120
|
|
||||||
|
|
||||||
# dns:
|
|
||||||
# image: strm/dnsmasq
|
|
||||||
# volumes:
|
|
||||||
# - ./dnsmasq.conf:/etc/dnsmasq.d/local.conf
|
|
||||||
# ports:
|
|
||||||
# - "53:53/udp"
|
|
||||||
# cap_add:
|
|
||||||
# - NET_ADMIN
|
|
||||||
# depends_on:
|
|
||||||
# - nginx
|
|
||||||
|
|
||||||
# nginx:
|
|
||||||
# image: nginx:alpine
|
|
||||||
# volumes:
|
|
||||||
# - ./nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
|
||||||
# - ./nginx/conf.d:/etc/nginx/conf.d:ro
|
|
||||||
# - ./certs:/etc/nginx/certs:ro
|
|
||||||
# network_mode: host
|
|
||||||
|
|
||||||
networks:
|
networks:
|
||||||
dev:
|
dev:
|
||||||
|
|
||||||
volumes:
|
volumes:
|
||||||
postgres_data:
|
postgres_data:
|
||||||
manticoresearch_data:
|
|
||||||
elasticsearch_data:
|
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
log-queries
|
|
||||||
address=/dev.affine.fail/127.0.0.1
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
user nginx;
|
|
||||||
worker_processes auto;
|
|
||||||
|
|
||||||
error_log /var/log/nginx/error.log;
|
|
||||||
pid /var/run/nginx.pid;
|
|
||||||
|
|
||||||
events {
|
|
||||||
worker_connections 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
http {
|
|
||||||
include mime.types;
|
|
||||||
default_type application/octet-stream;
|
|
||||||
|
|
||||||
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
||||||
'$status $body_bytes_sent "$http_referer" '
|
|
||||||
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
||||||
access_log /var/log/nginx/access.log main;
|
|
||||||
|
|
||||||
sendfile on;
|
|
||||||
keepalive_timeout 65;
|
|
||||||
types_hash_max_size 2048;
|
|
||||||
client_max_body_size 512M;
|
|
||||||
server_names_hash_bucket_size 128;
|
|
||||||
ssi on;
|
|
||||||
gzip on;
|
|
||||||
include "/etc/nginx/conf.d/*";
|
|
||||||
}
|
|
||||||
@@ -1,27 +0,0 @@
|
|||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name DEV_DOMAIN;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
return 301 https://$host$request_uri;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
server {
|
|
||||||
listen 443 ssl;
|
|
||||||
http2 on;
|
|
||||||
ssl_certificate /etc/nginx/certs/$host/crt;
|
|
||||||
ssl_certificate_key /etc/nginx/certs/$host/key;
|
|
||||||
server_name DEV_DOMAIN;
|
|
||||||
|
|
||||||
location / {
|
|
||||||
proxy_pass http://localhost:8080;
|
|
||||||
proxy_set_header Host $host;
|
|
||||||
proxy_set_header X-Real-IP $remote_addr;
|
|
||||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
|
||||||
proxy_set_header X-Forwarded-Proto $scheme;
|
|
||||||
proxy_set_header Upgrade $http_upgrade;
|
|
||||||
proxy_set_header Connection "upgrade";
|
|
||||||
resolver 127.0.0.1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,25 +0,0 @@
|
|||||||
[req]
|
|
||||||
distinguished_name = req_distinguished_name
|
|
||||||
req_extensions = v3_req
|
|
||||||
|
|
||||||
[req_distinguished_name]
|
|
||||||
countryName = Country Name (2 letter code)
|
|
||||||
countryName_default = US
|
|
||||||
stateOrProvinceName = State or Province Name (full name)
|
|
||||||
stateOrProvinceName_default = MN
|
|
||||||
localityName = Locality Name (eg, city)
|
|
||||||
localityName_default = Minneapolis
|
|
||||||
organizationalUnitName = Organizational Unit Name (eg, section)
|
|
||||||
organizationalUnitName_default = Domain Control Validated
|
|
||||||
commonName = Internet Widgits Ltd
|
|
||||||
commonName_max = 64
|
|
||||||
|
|
||||||
[ v3_req ]
|
|
||||||
# Extensions to add to a certificate request
|
|
||||||
basicConstraints = CA:FALSE
|
|
||||||
keyUsage = nonRepudiation, digitalSignature, keyEncipherment
|
|
||||||
subjectAltName = @alt_names
|
|
||||||
|
|
||||||
[alt_names]
|
|
||||||
DNS.1 = DEV_DOMAIN
|
|
||||||
DNS.2 = *.DEV_DOMAIN
|
|
||||||
@@ -20,4 +20,4 @@ CONFIG_LOCATION=~/.affine/self-host/config
|
|||||||
# database credentials
|
# database credentials
|
||||||
DB_USERNAME=affine
|
DB_USERNAME=affine
|
||||||
DB_PASSWORD=
|
DB_PASSWORD=
|
||||||
DB_DATABASE=affine
|
DB_DATABASE=affine
|
||||||
@@ -1 +0,0 @@
|
|||||||
.env
|
|
||||||
@@ -21,7 +21,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- REDIS_SERVER_HOST=redis
|
- REDIS_SERVER_HOST=redis
|
||||||
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
|
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
|
||||||
- AFFINE_INDEXER_ENABLED=false
|
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
affine_migration:
|
affine_migration:
|
||||||
@@ -37,7 +36,6 @@ services:
|
|||||||
environment:
|
environment:
|
||||||
- REDIS_SERVER_HOST=redis
|
- REDIS_SERVER_HOST=redis
|
||||||
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
|
- DATABASE_URL=postgresql://${DB_USERNAME}:${DB_PASSWORD}@postgres:5432/${DB_DATABASE:-affine}
|
||||||
- AFFINE_INDEXER_ENABLED=false
|
|
||||||
depends_on:
|
depends_on:
|
||||||
postgres:
|
postgres:
|
||||||
condition: service_healthy
|
condition: service_healthy
|
||||||
@@ -55,7 +53,7 @@ services:
|
|||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
|
|
||||||
postgres:
|
postgres:
|
||||||
image: pgvector/pgvector:pg16
|
image: postgres:16
|
||||||
container_name: affine_postgres
|
container_name: affine_postgres
|
||||||
volumes:
|
volumes:
|
||||||
- ${DB_DATA_LOCATION}:/var/lib/postgresql/data
|
- ${DB_DATA_LOCATION}:/var/lib/postgresql/data
|
||||||
|
|||||||
+31
-202
@@ -31,13 +31,9 @@
|
|||||||
"properties": {
|
"properties": {
|
||||||
"queue": {
|
"queue": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for job queues\n@default {\"attempts\":5,\"backoff\":{\"type\":\"exponential\",\"delay\":1000},\"removeOnComplete\":true,\"removeOnFail\":{\"age\":86400,\"count\":500}}\n@link https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html",
|
"description": "The config for job queues\n@default {\"attempts\":5,\"removeOnComplete\":true,\"removeOnFail\":{\"age\":86400,\"count\":500}}\n@link https://api.docs.bullmq.io/interfaces/v5.QueueOptions.html",
|
||||||
"default": {
|
"default": {
|
||||||
"attempts": 5,
|
"attempts": 5,
|
||||||
"backoff": {
|
|
||||||
"type": "exponential",
|
|
||||||
"delay": 1000
|
|
||||||
},
|
|
||||||
"removeOnComplete": true,
|
"removeOnComplete": true,
|
||||||
"removeOnFail": {
|
"removeOnFail": {
|
||||||
"age": 86400,
|
"age": 86400,
|
||||||
@@ -52,19 +48,7 @@
|
|||||||
},
|
},
|
||||||
"queues.copilot": {
|
"queues.copilot": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for copilot job queue\n@default {\"concurrency\":10}",
|
"description": "The config for copilot job queue\n@default {\"concurrency\":1}",
|
||||||
"properties": {
|
|
||||||
"concurrency": {
|
|
||||||
"type": "number"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"default": {
|
|
||||||
"concurrency": 10
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"queues.doc": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The config for doc job queue\n@default {\"concurrency\":1}",
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"concurrency": {
|
"concurrency": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
@@ -74,9 +58,9 @@
|
|||||||
"concurrency": 1
|
"concurrency": 1
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"queues.indexer": {
|
"queues.doc": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for indexer job queue\n@default {\"concurrency\":1}",
|
"description": "The config for doc job queue\n@default {\"concurrency\":1}",
|
||||||
"properties": {
|
"properties": {
|
||||||
"concurrency": {
|
"concurrency": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
@@ -139,6 +123,32 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"websocket": {
|
||||||
|
"type": "object",
|
||||||
|
"description": "Configuration for websocket module",
|
||||||
|
"properties": {
|
||||||
|
"transports": {
|
||||||
|
"type": "array",
|
||||||
|
"description": "The enabled transports for accepting websocket traffics.\n@default [\"websocket\",\"polling\"]\n@link https://docs.nestjs.com/websockets/gateways#transports",
|
||||||
|
"items": {
|
||||||
|
"type": "string",
|
||||||
|
"enum": [
|
||||||
|
"websocket",
|
||||||
|
"polling"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"default": [
|
||||||
|
"websocket",
|
||||||
|
"polling"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"maxHttpBufferSize": {
|
||||||
|
"type": "number",
|
||||||
|
"description": "How many bytes or characters a message can be, before closing the session (to avoid DoS).\n@default 100000000",
|
||||||
|
"default": 100000000
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"auth": {
|
"auth": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Configuration for auth module",
|
"description": "Configuration for auth module",
|
||||||
@@ -491,32 +501,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"websocket": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "Configuration for websocket module",
|
|
||||||
"properties": {
|
|
||||||
"transports": {
|
|
||||||
"type": "array",
|
|
||||||
"description": "The enabled transports for accepting websocket traffics.\n@default [\"websocket\",\"polling\"]\n@link https://docs.nestjs.com/websockets/gateways#transports",
|
|
||||||
"items": {
|
|
||||||
"type": "string",
|
|
||||||
"enum": [
|
|
||||||
"websocket",
|
|
||||||
"polling"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"default": [
|
|
||||||
"websocket",
|
|
||||||
"polling"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"maxHttpBufferSize": {
|
|
||||||
"type": "number",
|
|
||||||
"description": "How many bytes or characters a message can be, before closing the session (to avoid DoS).\n@default 100000000",
|
|
||||||
"default": 100000000
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"server": {
|
"server": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Configuration for server module",
|
"description": "Configuration for server module",
|
||||||
@@ -643,41 +627,6 @@
|
|||||||
"apiKey": ""
|
"apiKey": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"providers.geminiVertex": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The config for the google vertex provider.\n@default {}",
|
|
||||||
"properties": {
|
|
||||||
"location": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The location of the google vertex provider."
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The project name of the google vertex provider."
|
|
||||||
},
|
|
||||||
"googleAuthOptions": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The google auth options for the google vertex provider.",
|
|
||||||
"properties": {
|
|
||||||
"credentials": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The credentials for the google vertex provider.",
|
|
||||||
"properties": {
|
|
||||||
"client_email": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The client email for the google vertex provider."
|
|
||||||
},
|
|
||||||
"private_key": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The private key for the google vertex provider."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"default": {}
|
|
||||||
},
|
|
||||||
"providers.perplexity": {
|
"providers.perplexity": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for the perplexity provider.\n@default {\"apiKey\":\"\"}",
|
"description": "The config for the perplexity provider.\n@default {\"apiKey\":\"\"}",
|
||||||
@@ -685,48 +634,6 @@
|
|||||||
"apiKey": ""
|
"apiKey": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"providers.anthropic": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The config for the anthropic provider.\n@default {\"apiKey\":\"\"}",
|
|
||||||
"default": {
|
|
||||||
"apiKey": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"providers.anthropicVertex": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The config for the google vertex provider.\n@default {}",
|
|
||||||
"properties": {
|
|
||||||
"location": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The location of the google vertex provider."
|
|
||||||
},
|
|
||||||
"project": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The project name of the google vertex provider."
|
|
||||||
},
|
|
||||||
"googleAuthOptions": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The google auth options for the google vertex provider.",
|
|
||||||
"properties": {
|
|
||||||
"credentials": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The credentials for the google vertex provider.",
|
|
||||||
"properties": {
|
|
||||||
"client_email": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The client email for the google vertex provider."
|
|
||||||
},
|
|
||||||
"private_key": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "The private key for the google vertex provider."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"default": {}
|
|
||||||
},
|
|
||||||
"unsplash": {
|
"unsplash": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for the unsplash key.\n@default {\"key\":\"\"}",
|
"description": "The config for the unsplash key.\n@default {\"key\":\"\"}",
|
||||||
@@ -734,13 +641,6 @@
|
|||||||
"key": ""
|
"key": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"exa": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "The config for the exa web search key.\n@default {\"key\":\"\"}",
|
|
||||||
"default": {
|
|
||||||
"key": ""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"storage": {
|
"storage": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "The config for the storage provider.\n@default {\"provider\":\"fs\",\"bucket\":\"copilot\",\"config\":{\"path\":\"~/.affine/storage\"}}",
|
"description": "The config for the storage provider.\n@default {\"provider\":\"fs\",\"bucket\":\"copilot\",\"config\":{\"path\":\"~/.affine/storage\"}}",
|
||||||
@@ -880,47 +780,6 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"indexer": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "Configuration for indexer module",
|
|
||||||
"properties": {
|
|
||||||
"enabled": {
|
|
||||||
"type": "boolean",
|
|
||||||
"description": "Enable indexer plugin\n@default false\n@environment `AFFINE_INDEXER_ENABLED`",
|
|
||||||
"default": false
|
|
||||||
},
|
|
||||||
"provider.type": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Indexer search service provider name\n@default \"manticoresearch\"\n@environment `AFFINE_INDEXER_SEARCH_PROVIDER`",
|
|
||||||
"default": "manticoresearch"
|
|
||||||
},
|
|
||||||
"provider.endpoint": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Indexer search service endpoint\n@default \"http://localhost:9308\"\n@environment `AFFINE_INDEXER_SEARCH_ENDPOINT`",
|
|
||||||
"default": "http://localhost:9308"
|
|
||||||
},
|
|
||||||
"provider.apiKey": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Indexer search service api key. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_API_KEY`\n@link https://www.elastic.co/guide/server/current/api-key.html",
|
|
||||||
"default": ""
|
|
||||||
},
|
|
||||||
"provider.username": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Indexer search service auth username, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_USERNAME`\n@link https://www.elastic.co/guide/en/elasticsearch/reference/current/http-clients.html",
|
|
||||||
"default": ""
|
|
||||||
},
|
|
||||||
"provider.password": {
|
|
||||||
"type": "string",
|
|
||||||
"description": "Indexer search service auth password, if not set, basic auth will be disabled. Optional for elasticsearch\n@default \"\"\n@environment `AFFINE_INDEXER_SEARCH_PASSWORD`",
|
|
||||||
"default": ""
|
|
||||||
},
|
|
||||||
"autoIndex.batchSize": {
|
|
||||||
"type": "number",
|
|
||||||
"description": "Number of workspaces automatically indexed per batch\n@default 10",
|
|
||||||
"default": 10
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"oauth": {
|
"oauth": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "Configuration for oauth module",
|
"description": "Configuration for oauth module",
|
||||||
@@ -965,43 +824,13 @@
|
|||||||
},
|
},
|
||||||
"providers.oidc": {
|
"providers.oidc": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"description": "OIDC OAuth provider config\n@default {\"clientId\":\"\",\"clientSecret\":\"\",\"issuer\":\"\",\"args\":{}}\n@link https://openid.net/specs/openid-connect-core-1_0.html",
|
"description": "OIDC OAuth provider config\n@default {\"clientId\":\"\",\"clientSecret\":\"\",\"issuer\":\"\",\"args\":{}}",
|
||||||
"properties": {
|
|
||||||
"clientId": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"clientSecret": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"args": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"default": {
|
"default": {
|
||||||
"clientId": "",
|
"clientId": "",
|
||||||
"clientSecret": "",
|
"clientSecret": "",
|
||||||
"issuer": "",
|
"issuer": "",
|
||||||
"args": {}
|
"args": {}
|
||||||
}
|
}
|
||||||
},
|
|
||||||
"providers.apple": {
|
|
||||||
"type": "object",
|
|
||||||
"description": "Apple OAuth provider config\n@default {\"clientId\":\"\",\"clientSecret\":\"\"}\n@link https://developer.apple.com/documentation/sign_in_with_apple/sign_in_with_apple_js/implementing_sign_in_with_apple_in_your_app",
|
|
||||||
"properties": {
|
|
||||||
"clientId": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"clientSecret": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"args": {
|
|
||||||
"type": "object"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"default": {
|
|
||||||
"clientId": "",
|
|
||||||
"clientSecret": ""
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ const {
|
|||||||
REDIS_SERVER_HOST,
|
REDIS_SERVER_HOST,
|
||||||
REDIS_SERVER_PASSWORD,
|
REDIS_SERVER_PASSWORD,
|
||||||
STATIC_IP_NAME,
|
STATIC_IP_NAME,
|
||||||
AFFINE_INDEXER_SEARCH_PROVIDER,
|
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT,
|
|
||||||
AFFINE_INDEXER_SEARCH_API_KEY,
|
|
||||||
} = process.env;
|
} = process.env;
|
||||||
|
|
||||||
const buildType = BUILD_TYPE || 'canary';
|
const buildType = BUILD_TYPE || 'canary';
|
||||||
@@ -84,11 +81,6 @@ const createHelmCommand = ({ isDryRun }) => {
|
|||||||
`--set-string global.redis.password="${REDIS_SERVER_PASSWORD}"`,
|
`--set-string global.redis.password="${REDIS_SERVER_PASSWORD}"`,
|
||||||
]
|
]
|
||||||
: [];
|
: [];
|
||||||
const indexerOptions = [
|
|
||||||
`--set-string global.indexer.provider="${AFFINE_INDEXER_SEARCH_PROVIDER}"`,
|
|
||||||
`--set-string global.indexer.endpoint="${AFFINE_INDEXER_SEARCH_ENDPOINT}"`,
|
|
||||||
`--set-string global.indexer.apiKey="${AFFINE_INDEXER_SEARCH_API_KEY}"`,
|
|
||||||
];
|
|
||||||
const serviceAnnotations = [
|
const serviceAnnotations = [
|
||||||
`--set-json web.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
`--set-json web.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
||||||
`--set-json graphql.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
`--set-json graphql.serviceAccount.annotations="{ \\"iam.gke.io/gcp-service-account\\": \\"${APP_IAM_ACCOUNT}\\" }"`,
|
||||||
@@ -138,7 +130,6 @@ const createHelmCommand = ({ isDryRun }) => {
|
|||||||
`--set-string global.ingress.host="${host}"`,
|
`--set-string global.ingress.host="${host}"`,
|
||||||
`--set-string global.version="${APP_VERSION}"`,
|
`--set-string global.version="${APP_VERSION}"`,
|
||||||
...redisAndPostgres,
|
...redisAndPostgres,
|
||||||
...indexerOptions,
|
|
||||||
`--set web.replicaCount=${replica.web}`,
|
`--set web.replicaCount=${replica.web}`,
|
||||||
`--set-string web.image.tag="${imageTag}"`,
|
`--set-string web.image.tag="${imageTag}"`,
|
||||||
`--set graphql.replicaCount=${replica.graphql}`,
|
`--set graphql.replicaCount=${replica.graphql}`,
|
||||||
|
|||||||
@@ -4,11 +4,6 @@ description: 'Prepare Server Test Environment'
|
|||||||
runs:
|
runs:
|
||||||
using: 'composite'
|
using: 'composite'
|
||||||
steps:
|
steps:
|
||||||
- name: Bundle @affine/reader
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
yarn affine @affine/reader build
|
|
||||||
|
|
||||||
- name: Initialize database
|
- name: Initialize database
|
||||||
shell: bash
|
shell: bash
|
||||||
run: |
|
run: |
|
||||||
@@ -26,10 +21,13 @@ runs:
|
|||||||
yarn affine @affine/server prisma generate
|
yarn affine @affine/server prisma generate
|
||||||
yarn affine @affine/server prisma migrate deploy
|
yarn affine @affine/server prisma migrate deploy
|
||||||
yarn affine @affine/server data-migration run
|
yarn affine @affine/server data-migration run
|
||||||
|
|
||||||
- name: Import config
|
- name: Import config
|
||||||
shell: bash
|
shell: bash
|
||||||
env:
|
|
||||||
DEFAULT_CONFIG: '{}'
|
|
||||||
run: |
|
run: |
|
||||||
printf '%s\n' "${SERVER_CONFIG:-$DEFAULT_CONFIG}" > ./packages/backend/server/config.json
|
printf '{"copilot":{"enabled":true,"providers.fal":{"apiKey":"%s"},"providers.gemini":{"apiKey":"%s"},"providers.openai":{"apiKey":"%s"},"providers.perplexity":{"apiKey":"%s"},"providers.anthropic":{"apiKey":"%s"},"exa":{"key":"%s"}}}' \
|
||||||
|
"$COPILOT_FAL_API_KEY" \
|
||||||
|
"$COPILOT_GOOGLE_API_KEY" \
|
||||||
|
"$COPILOT_OPENAI_API_KEY" \
|
||||||
|
"$COPILOT_PERPLEXITY_API_KEY" \
|
||||||
|
"$COPILOT_ANTHROPIC_API_KEY" \
|
||||||
|
"$COPILOT_EXA_API_KEY" > ./packages/backend/server/config.json
|
||||||
|
|||||||
@@ -69,15 +69,6 @@ spec:
|
|||||||
key: redis-password
|
key: redis-password
|
||||||
- name: REDIS_SERVER_DATABASE
|
- name: REDIS_SERVER_DATABASE
|
||||||
value: "{{ .Values.global.redis.database }}"
|
value: "{{ .Values.global.redis.database }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_PROVIDER
|
|
||||||
value: "{{ .Values.global.indexer.provider }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: indexer
|
|
||||||
key: indexer-apiKey
|
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.global.docService.port }}"
|
value: "{{ .Values.global.docService.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
@@ -95,13 +86,11 @@ spec:
|
|||||||
path: /info
|
path: /info
|
||||||
port: http
|
port: http
|
||||||
initialDelaySeconds: {{ .Values.probe.initialDelaySeconds }}
|
initialDelaySeconds: {{ .Values.probe.initialDelaySeconds }}
|
||||||
timeoutSeconds: {{ .Values.probe.timeoutSeconds }}
|
|
||||||
readinessProbe:
|
readinessProbe:
|
||||||
httpGet:
|
httpGet:
|
||||||
path: /info
|
path: /info
|
||||||
port: http
|
port: http
|
||||||
initialDelaySeconds: {{ .Values.probe.initialDelaySeconds }}
|
initialDelaySeconds: {{ .Values.probe.initialDelaySeconds }}
|
||||||
timeoutSeconds: {{ .Values.probe.timeoutSeconds }}
|
|
||||||
resources:
|
resources:
|
||||||
{{- toYaml .Values.resources | nindent 12 }}
|
{{- toYaml .Values.resources | nindent 12 }}
|
||||||
{{- with .Values.nodeSelector }}
|
{{- with .Values.nodeSelector }}
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ resources:
|
|||||||
|
|
||||||
probe:
|
probe:
|
||||||
initialDelaySeconds: 20
|
initialDelaySeconds: 20
|
||||||
timeoutSeconds: 5
|
|
||||||
|
|
||||||
nodeSelector: {}
|
nodeSelector: {}
|
||||||
tolerations: []
|
tolerations: []
|
||||||
|
|||||||
@@ -67,15 +67,6 @@ spec:
|
|||||||
key: redis-password
|
key: redis-password
|
||||||
- name: REDIS_SERVER_DATABASE
|
- name: REDIS_SERVER_DATABASE
|
||||||
value: "{{ .Values.global.redis.database }}"
|
value: "{{ .Values.global.redis.database }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_PROVIDER
|
|
||||||
value: "{{ .Values.global.indexer.provider }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: indexer
|
|
||||||
key: indexer-apiKey
|
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
|
|||||||
@@ -44,15 +44,6 @@ spec:
|
|||||||
secretKeyRef:
|
secretKeyRef:
|
||||||
name: redis
|
name: redis
|
||||||
key: redis-password
|
key: redis-password
|
||||||
- name: AFFINE_INDEXER_SEARCH_PROVIDER
|
|
||||||
value: "{{ .Values.global.indexer.provider }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: indexer
|
|
||||||
key: indexer-apiKey
|
|
||||||
resources:
|
resources:
|
||||||
requests:
|
requests:
|
||||||
cpu: '100m'
|
cpu: '100m'
|
||||||
|
|||||||
@@ -69,15 +69,6 @@ spec:
|
|||||||
key: redis-password
|
key: redis-password
|
||||||
- name: REDIS_SERVER_DATABASE
|
- name: REDIS_SERVER_DATABASE
|
||||||
value: "{{ .Values.global.redis.database }}"
|
value: "{{ .Values.global.redis.database }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_PROVIDER
|
|
||||||
value: "{{ .Values.global.indexer.provider }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: indexer
|
|
||||||
key: indexer-apiKey
|
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_SUB_PATH
|
- name: AFFINE_SERVER_SUB_PATH
|
||||||
|
|||||||
@@ -69,15 +69,6 @@ spec:
|
|||||||
key: redis-password
|
key: redis-password
|
||||||
- name: REDIS_SERVER_DATABASE
|
- name: REDIS_SERVER_DATABASE
|
||||||
value: "{{ .Values.global.redis.database }}"
|
value: "{{ .Values.global.redis.database }}"
|
||||||
- name: AFFINE_INDEXER_SEARCH_PROVIDER
|
|
||||||
value: "{{ .Values.global.indexer.provider }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_ENDPOINT
|
|
||||||
value: "{{ .Values.global.indexer.endpoint }}"
|
|
||||||
- name: AFFINE_INDEXER_SEARCH_API_KEY
|
|
||||||
valueFrom:
|
|
||||||
secretKeyRef:
|
|
||||||
name: indexer
|
|
||||||
key: indexer-apiKey
|
|
||||||
- name: AFFINE_SERVER_PORT
|
- name: AFFINE_SERVER_PORT
|
||||||
value: "{{ .Values.service.port }}"
|
value: "{{ .Values.service.port }}"
|
||||||
- name: AFFINE_SERVER_HOST
|
- name: AFFINE_SERVER_HOST
|
||||||
|
|||||||
@@ -1,13 +0,0 @@
|
|||||||
{{- if .Values.global.indexer.apiKey -}}
|
|
||||||
apiVersion: v1
|
|
||||||
kind: Secret
|
|
||||||
metadata:
|
|
||||||
name: indexer
|
|
||||||
annotations:
|
|
||||||
"helm.sh/hook": pre-install,pre-upgrade
|
|
||||||
"helm.sh/hook-weight": "-2"
|
|
||||||
"helm.sh/hook-delete-policy": before-hook-creation
|
|
||||||
type: Opaque
|
|
||||||
data:
|
|
||||||
indexer-apiKey: {{ .Values.global.indexer.apiKey | b64enc }}
|
|
||||||
{{- end }}
|
|
||||||
@@ -1,13 +0,0 @@
|
|||||||
{{- if eq .Values.global.deployment.platform "gcp" -}}
|
|
||||||
apiVersion: monitoring.googleapis.com/v1
|
|
||||||
kind: PodMonitoring
|
|
||||||
metadata:
|
|
||||||
name: "{{ .Release.Name }}-monitoring"
|
|
||||||
spec:
|
|
||||||
selector:
|
|
||||||
matchLabels:
|
|
||||||
app.kubernetes.io/instance: {{ .Release.Name }}
|
|
||||||
endpoints:
|
|
||||||
- port: 9464
|
|
||||||
interval: 30s
|
|
||||||
{{- end }}
|
|
||||||
@@ -21,11 +21,6 @@ global:
|
|||||||
username: ''
|
username: ''
|
||||||
password: ''
|
password: ''
|
||||||
database: 0
|
database: 0
|
||||||
indexer:
|
|
||||||
provider: ''
|
|
||||||
endpoint: ''
|
|
||||||
username: ''
|
|
||||||
password: ''
|
|
||||||
docService:
|
docService:
|
||||||
name: 'affine-doc'
|
name: 'affine-doc'
|
||||||
port: 3020
|
port: 3020
|
||||||
|
|||||||
@@ -113,7 +113,6 @@ jobs:
|
|||||||
build-server-native:
|
build-server-native:
|
||||||
name: Build Server native - ${{ matrix.targets.name }}
|
name: Build Server native - ${{ matrix.targets.name }}
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
environment: ${{ github.event.inputs.flavor }}
|
|
||||||
strategy:
|
strategy:
|
||||||
fail-fast: false
|
fail-fast: false
|
||||||
matrix:
|
matrix:
|
||||||
@@ -137,9 +136,6 @@ jobs:
|
|||||||
extra-flags: workspaces focus @affine/server-native
|
extra-flags: workspaces focus @affine/server-native
|
||||||
- name: Build Rust
|
- name: Build Rust
|
||||||
uses: ./.github/actions/build-rust
|
uses: ./.github/actions/build-rust
|
||||||
env:
|
|
||||||
AFFINE_PRO_PUBLIC_KEY: ${{ secrets.AFFINE_PRO_PUBLIC_KEY }}
|
|
||||||
AFFINE_PRO_LICENSE_AES_KEY: ${{ secrets.AFFINE_PRO_LICENSE_AES_KEY }}
|
|
||||||
with:
|
with:
|
||||||
target: ${{ matrix.targets.name }}
|
target: ${{ matrix.targets.name }}
|
||||||
package: '@affine/server-native'
|
package: '@affine/server-native'
|
||||||
@@ -176,8 +172,6 @@ jobs:
|
|||||||
path: ./packages/backend/native
|
path: ./packages/backend/native
|
||||||
- name: List server-native files
|
- name: List server-native files
|
||||||
run: ls -alh ./packages/backend/native
|
run: ls -alh ./packages/backend/native
|
||||||
- name: Build @affine/reader
|
|
||||||
run: yarn workspace @affine/reader build
|
|
||||||
- name: Build Server
|
- name: Build Server
|
||||||
run: yarn workspace @affine/server build
|
run: yarn workspace @affine/server build
|
||||||
- name: Upload server dist
|
- name: Upload server dist
|
||||||
@@ -259,9 +253,6 @@ jobs:
|
|||||||
- name: Generate Prisma client
|
- name: Generate Prisma client
|
||||||
run: yarn workspace @affine/server prisma generate
|
run: yarn workspace @affine/server prisma generate
|
||||||
|
|
||||||
- name: Mv node_modules
|
|
||||||
run: mv ./node_modules ./packages/backend/server
|
|
||||||
|
|
||||||
- name: Setup Version
|
- name: Setup Version
|
||||||
id: version
|
id: version
|
||||||
uses: ./.github/actions/setup-version
|
uses: ./.github/actions/setup-version
|
||||||
|
|||||||
@@ -20,7 +20,6 @@ env:
|
|||||||
COVERAGE: true
|
COVERAGE: true
|
||||||
MACOSX_DEPLOYMENT_TARGET: '10.13'
|
MACOSX_DEPLOYMENT_TARGET: '10.13'
|
||||||
DEPLOYMENT_TYPE: affine
|
DEPLOYMENT_TYPE: affine
|
||||||
AFFINE_INDEXER_ENABLED: true
|
|
||||||
|
|
||||||
concurrency:
|
concurrency:
|
||||||
group: ${{ github.workflow }}-${{ github.ref }}
|
group: ${{ github.workflow }}-${{ github.ref }}
|
||||||
@@ -126,7 +125,6 @@ jobs:
|
|||||||
- name: Run BS Docs Build
|
- name: Run BS Docs Build
|
||||||
run: |
|
run: |
|
||||||
yarn affine bs-docs build
|
yarn affine bs-docs build
|
||||||
git checkout packages/frontend/i18n/src/i18n-completenesses.json
|
|
||||||
git status --porcelain | grep . && {
|
git status --porcelain | grep . && {
|
||||||
echo "Run 'yarn typecheck && yarn affine bs-docs build' and make sure all changes are submitted"
|
echo "Run 'yarn typecheck && yarn affine bs-docs build' and make sure all changes are submitted"
|
||||||
exit 1
|
exit 1
|
||||||
@@ -152,15 +150,13 @@ jobs:
|
|||||||
- name: Clippy
|
- name: Clippy
|
||||||
run: |
|
run: |
|
||||||
rustup component add clippy
|
rustup component add clippy
|
||||||
cargo clippy --workspace --exclude affine_server_native --all-targets --all-features -- -D warnings
|
cargo clippy --all-targets --all-features -- -D warnings
|
||||||
cargo clippy -p affine_server_native --all-targets --all-features -- -D warnings
|
|
||||||
|
|
||||||
check-git-status:
|
check-git-status:
|
||||||
name: Check Git Status
|
name: Check Git Status
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- optimize_ci
|
- optimize_ci
|
||||||
- build-server-native
|
|
||||||
if: needs.optimize_ci.outputs.skip == 'false'
|
if: needs.optimize_ci.outputs.skip == 'false'
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -169,26 +165,13 @@ jobs:
|
|||||||
with:
|
with:
|
||||||
full-cache: true
|
full-cache: true
|
||||||
|
|
||||||
- name: Download server-native.node
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: server-native.node
|
|
||||||
path: ./packages/backend/native
|
|
||||||
|
|
||||||
- name: Bundle @affine/reader
|
|
||||||
shell: bash
|
|
||||||
run: |
|
|
||||||
yarn workspace @affine/reader build
|
|
||||||
|
|
||||||
- name: Run Check
|
- name: Run Check
|
||||||
run: |
|
run: |
|
||||||
yarn affine init
|
yarn affine init
|
||||||
yarn affine gql build
|
yarn affine gql build
|
||||||
yarn affine i18n build
|
yarn affine i18n build
|
||||||
yarn affine server genconfig
|
|
||||||
git checkout packages/frontend/i18n/src/i18n-completenesses.json
|
|
||||||
git status --porcelain | grep . && {
|
git status --porcelain | grep . && {
|
||||||
echo "Run 'yarn affine init && yarn affine gql build && yarn affine i18n build && yarn affine server genconfig' and make sure all changes are submitted"
|
echo "Run 'yarn affine init && yarn affine gql build && yarn affine i18n build' and make sure all changes are submitted"
|
||||||
exit 1
|
exit 1
|
||||||
} || {
|
} || {
|
||||||
echo "All changes are submitted"
|
echo "All changes are submitted"
|
||||||
@@ -586,10 +569,6 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 1025:1025
|
- 1025:1025
|
||||||
- 8025:8025
|
- 8025:8025
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -624,90 +603,6 @@ jobs:
|
|||||||
name: affine
|
name: affine
|
||||||
fail_ci_if_error: false
|
fail_ci_if_error: false
|
||||||
|
|
||||||
server-test-elasticsearch:
|
|
||||||
name: Server Test with Elasticsearch
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
needs:
|
|
||||||
- optimize_ci
|
|
||||||
- build-server-native
|
|
||||||
if: needs.optimize_ci.outputs.skip == 'false'
|
|
||||||
strategy:
|
|
||||||
fail-fast: false
|
|
||||||
env:
|
|
||||||
NODE_ENV: test
|
|
||||||
DATABASE_URL: postgresql://affine:affine@localhost:5432/affine
|
|
||||||
REDIS_SERVER_HOST: localhost
|
|
||||||
AFFINE_INDEXER_SEARCH_PROVIDER: elasticsearch
|
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT: http://localhost:9200
|
|
||||||
services:
|
|
||||||
postgres:
|
|
||||||
image: pgvector/pgvector:pg16
|
|
||||||
env:
|
|
||||||
POSTGRES_PASSWORD: affine
|
|
||||||
options: >-
|
|
||||||
--health-cmd pg_isready
|
|
||||||
--health-interval 10s
|
|
||||||
--health-timeout 5s
|
|
||||||
--health-retries 5
|
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
redis:
|
|
||||||
image: redis
|
|
||||||
ports:
|
|
||||||
- 6379:6379
|
|
||||||
mailer:
|
|
||||||
image: mailhog/mailhog
|
|
||||||
ports:
|
|
||||||
- 1025:1025
|
|
||||||
- 8025:8025
|
|
||||||
steps:
|
|
||||||
# https://github.com/elastic/elastic-github-actions/blob/master/elasticsearch/README.md
|
|
||||||
- name: Configure sysctl limits for Elasticsearch
|
|
||||||
run: |
|
|
||||||
sudo swapoff -a
|
|
||||||
sudo sysctl -w vm.swappiness=1
|
|
||||||
sudo sysctl -w fs.file-max=262144
|
|
||||||
sudo sysctl -w vm.max_map_count=262144
|
|
||||||
|
|
||||||
- name: Runs Elasticsearch
|
|
||||||
uses: elastic/elastic-github-actions/elasticsearch@master
|
|
||||||
with:
|
|
||||||
stack-version: 9.0.1
|
|
||||||
security-enabled: false
|
|
||||||
|
|
||||||
- uses: actions/checkout@v4
|
|
||||||
|
|
||||||
- name: Setup Node.js
|
|
||||||
uses: ./.github/actions/setup-node
|
|
||||||
with:
|
|
||||||
electron-install: false
|
|
||||||
full-cache: true
|
|
||||||
|
|
||||||
- name: Download server-native.node
|
|
||||||
uses: actions/download-artifact@v4
|
|
||||||
with:
|
|
||||||
name: server-native.node
|
|
||||||
path: ./packages/backend/native
|
|
||||||
|
|
||||||
- name: Prepare Server Test Environment
|
|
||||||
uses: ./.github/actions/server-test-env
|
|
||||||
|
|
||||||
- name: Run server tests with elasticsearch only
|
|
||||||
run: yarn affine @affine/server test:coverage "**/*/*elasticsearch.spec.ts" --forbid-only
|
|
||||||
env:
|
|
||||||
CARGO_TARGET_DIR: '${{ github.workspace }}/target'
|
|
||||||
CI_NODE_INDEX: ${{ matrix.node_index }}
|
|
||||||
CI_NODE_TOTAL: ${{ matrix.total_nodes }}
|
|
||||||
|
|
||||||
- name: Upload server test coverage results
|
|
||||||
uses: codecov/codecov-action@v5
|
|
||||||
with:
|
|
||||||
token: ${{ secrets.CODECOV_TOKEN }}
|
|
||||||
files: ./packages/backend/server/.coverage/lcov.info
|
|
||||||
flags: server-test
|
|
||||||
name: affine
|
|
||||||
fail_ci_if_error: false
|
|
||||||
|
|
||||||
server-e2e-test:
|
server-e2e-test:
|
||||||
# the new version of server e2e test should be super fast, so sharding testing is not needed
|
# the new version of server e2e test should be super fast, so sharding testing is not needed
|
||||||
name: Server E2E Test
|
name: Server E2E Test
|
||||||
@@ -736,10 +631,6 @@ jobs:
|
|||||||
image: redis
|
image: redis
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -827,6 +718,7 @@ jobs:
|
|||||||
- optimize_ci
|
- optimize_ci
|
||||||
if: needs.optimize_ci.outputs.skip == 'false'
|
if: needs.optimize_ci.outputs.skip == 'false'
|
||||||
env:
|
env:
|
||||||
|
RUSTFLAGS: -D warnings
|
||||||
CARGO_TERM_COLOR: always
|
CARGO_TERM_COLOR: always
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
@@ -924,7 +816,7 @@ jobs:
|
|||||||
uses: taiki-e/install-action@nextest
|
uses: taiki-e/install-action@nextest
|
||||||
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: cargo nextest run --workspace --exclude affine_server_native --features use-as-lib --release --no-fail-fast
|
run: cargo nextest run --release --no-fail-fast
|
||||||
|
|
||||||
copilot-api-test:
|
copilot-api-test:
|
||||||
name: Server Copilot Api Test
|
name: Server Copilot Api Test
|
||||||
@@ -959,10 +851,6 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 1025:1025
|
- 1025:1025
|
||||||
- 8025:8025
|
- 8025:8025
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -1002,7 +890,12 @@ jobs:
|
|||||||
- name: Prepare Server Test Environment
|
- name: Prepare Server Test Environment
|
||||||
if: ${{ steps.check-blocksuite-update.outputs.skip != 'true' || steps.apifilter.outputs.changed == 'true' }}
|
if: ${{ steps.check-blocksuite-update.outputs.skip != 'true' || steps.apifilter.outputs.changed == 'true' }}
|
||||||
env:
|
env:
|
||||||
SERVER_CONFIG: ${{ secrets.TEST_SERVER_CONFIG }}
|
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
|
||||||
|
COPILOT_GOOGLE_API_KEY: ${{ secrets.COPILOT_GOOGLE_API_KEY }}
|
||||||
|
COPILOT_FAL_API_KEY: ${{ secrets.COPILOT_FAL_API_KEY }}
|
||||||
|
COPILOT_PERPLEXITY_API_KEY: ${{ secrets.COPILOT_PERPLEXITY_API_KEY }}
|
||||||
|
COPILOT_ANTHROPIC_API_KEY: ${{ secrets.COPILOT_ANTHROPIC_API_KEY }}
|
||||||
|
COPILOT_EXA_API_KEY: ${{ secrets.COPILOT_EXA_API_KEY }}
|
||||||
uses: ./.github/actions/server-test-env
|
uses: ./.github/actions/server-test-env
|
||||||
|
|
||||||
- name: Run server tests
|
- name: Run server tests
|
||||||
@@ -1053,10 +946,6 @@ jobs:
|
|||||||
image: redis
|
image: redis
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -1079,7 +968,6 @@ jobs:
|
|||||||
- 'packages/backend/server/src/plugins/copilot/**'
|
- 'packages/backend/server/src/plugins/copilot/**'
|
||||||
- 'packages/backend/server/tests/copilot.*'
|
- 'packages/backend/server/tests/copilot.*'
|
||||||
- 'packages/frontend/core/src/blocksuite/ai/**'
|
- 'packages/frontend/core/src/blocksuite/ai/**'
|
||||||
- 'packages/frontend/core/src/modules/workspace-indexer-embedding/**'
|
|
||||||
- 'tests/affine-cloud-copilot/**'
|
- 'tests/affine-cloud-copilot/**'
|
||||||
|
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -1101,7 +989,12 @@ jobs:
|
|||||||
- name: Prepare Server Test Environment
|
- name: Prepare Server Test Environment
|
||||||
if: ${{ steps.check-blocksuite-update.outputs.skip != 'true' || steps.e2efilter.outputs.changed == 'true' }}
|
if: ${{ steps.check-blocksuite-update.outputs.skip != 'true' || steps.e2efilter.outputs.changed == 'true' }}
|
||||||
env:
|
env:
|
||||||
SERVER_CONFIG: ${{ secrets.TEST_SERVER_CONFIG }}
|
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
|
||||||
|
COPILOT_GOOGLE_API_KEY: ${{ secrets.COPILOT_GOOGLE_API_KEY }}
|
||||||
|
COPILOT_FAL_API_KEY: ${{ secrets.COPILOT_FAL_API_KEY }}
|
||||||
|
COPILOT_PERPLEXITY_API_KEY: ${{ secrets.COPILOT_PERPLEXITY_API_KEY }}
|
||||||
|
COPILOT_ANTHROPIC_API_KEY: ${{ secrets.COPILOT_ANTHROPIC_API_KEY }}
|
||||||
|
COPILOT_EXA_API_KEY: ${{ secrets.COPILOT_EXA_API_KEY }}
|
||||||
uses: ./.github/actions/server-test-env
|
uses: ./.github/actions/server-test-env
|
||||||
|
|
||||||
- name: Run Copilot E2E Test ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
- name: Run Copilot E2E Test ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
||||||
@@ -1175,10 +1068,6 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 1025:1025
|
- 1025:1025
|
||||||
- 8025:8025
|
- 8025:8025
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -1348,13 +1237,6 @@ jobs:
|
|||||||
target: x86_64-unknown-linux-gnu,
|
target: x86_64-unknown-linux-gnu,
|
||||||
test: true,
|
test: true,
|
||||||
}
|
}
|
||||||
- {
|
|
||||||
os: windows-latest,
|
|
||||||
platform: windows,
|
|
||||||
arch: x64,
|
|
||||||
target: x86_64-pc-windows-msvc,
|
|
||||||
test: true,
|
|
||||||
}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Node.js
|
- name: Setup Node.js
|
||||||
@@ -1395,18 +1277,6 @@ jobs:
|
|||||||
HOIST_NODE_MODULES: 1
|
HOIST_NODE_MODULES: 1
|
||||||
run: yarn affine @affine/electron package --platform=darwin --arch=arm64
|
run: yarn affine @affine/electron package --platform=darwin --arch=arm64
|
||||||
|
|
||||||
- name: Make Bundle (Windows)
|
|
||||||
if: ${{ matrix.spec.target == 'x86_64-pc-windows-msvc' }}
|
|
||||||
shell: bash
|
|
||||||
env:
|
|
||||||
SKIP_BUNDLE: true
|
|
||||||
SKIP_WEB_BUILD: true
|
|
||||||
HOIST_NODE_MODULES: 1
|
|
||||||
run: |
|
|
||||||
rm -rf packages/frontend/apps/electron/node_modules/@affine/nbstore/node_modules/@blocksuite/affine/node_modules
|
|
||||||
rm -rf packages/frontend/apps/electron/node_modules/@affine/native/node_modules
|
|
||||||
yarn affine @affine/electron package --platform=win32 --arch=x64
|
|
||||||
|
|
||||||
- name: Make Bundle (Linux)
|
- name: Make Bundle (Linux)
|
||||||
run: |
|
run: |
|
||||||
sudo add-apt-repository universe
|
sudo add-apt-repository universe
|
||||||
|
|||||||
@@ -59,10 +59,6 @@ jobs:
|
|||||||
ports:
|
ports:
|
||||||
- 1025:1025
|
- 1025:1025
|
||||||
- 8025:8025
|
- 8025:8025
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -81,7 +77,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Prepare Server Test Environment
|
- name: Prepare Server Test Environment
|
||||||
env:
|
env:
|
||||||
SERVER_CONFIG: ${{ secrets.TEST_SERVER_CONFIG }}
|
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
|
||||||
|
COPILOT_FAL_API_KEY: ${{ secrets.COPILOT_FAL_API_KEY }}
|
||||||
|
COPILOT_GOOGLE_API_KEY: ${{ secrets.COPILOT_GOOGLE_API_KEY }}
|
||||||
|
COPILOT_PERPLEXITY_API_KEY: ${{ secrets.COPILOT_PERPLEXITY_API_KEY }}
|
||||||
|
COPILOT_ANTHROPIC_API_KEY: ${{ secrets.COPILOT_ANTHROPIC_API_KEY }}
|
||||||
|
COPILOT_EXA_API_KEY: ${{ secrets.COPILOT_EXA_API_KEY }}
|
||||||
uses: ./.github/actions/server-test-env
|
uses: ./.github/actions/server-test-env
|
||||||
|
|
||||||
- name: Run server tests
|
- name: Run server tests
|
||||||
@@ -129,10 +130,6 @@ jobs:
|
|||||||
image: redis
|
image: redis
|
||||||
ports:
|
ports:
|
||||||
- 6379:6379
|
- 6379:6379
|
||||||
indexer:
|
|
||||||
image: manticoresearch/manticore:9.3.2
|
|
||||||
ports:
|
|
||||||
- 9308:9308
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|
||||||
@@ -151,7 +148,12 @@ jobs:
|
|||||||
|
|
||||||
- name: Prepare Server Test Environment
|
- name: Prepare Server Test Environment
|
||||||
env:
|
env:
|
||||||
SERVER_CONFIG: ${{ secrets.TEST_SERVER_CONFIG }}
|
COPILOT_OPENAI_API_KEY: ${{ secrets.COPILOT_OPENAI_API_KEY }}
|
||||||
|
COPILOT_FAL_API_KEY: ${{ secrets.COPILOT_FAL_API_KEY }}
|
||||||
|
COPILOT_GOOGLE_API_KEY: ${{ secrets.COPILOT_GOOGLE_API_KEY }}
|
||||||
|
COPILOT_PERPLEXITY_API_KEY: ${{ secrets.COPILOT_PERPLEXITY_API_KEY }}
|
||||||
|
COPILOT_ANTHROPIC_API_KEY: ${{ secrets.COPILOT_ANTHROPIC_API_KEY }}
|
||||||
|
COPILOT_EXA_API_KEY: ${{ secrets.COPILOT_EXA_API_KEY }}
|
||||||
uses: ./.github/actions/server-test-env
|
uses: ./.github/actions/server-test-env
|
||||||
|
|
||||||
- name: Run Copilot E2E Test ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
- name: Run Copilot E2E Test ${{ matrix.shardIndex }}/${{ matrix.shardTotal }}
|
||||||
|
|||||||
@@ -103,9 +103,6 @@ jobs:
|
|||||||
CLOUD_SQL_IAM_ACCOUNT: ${{ secrets.CLOUD_SQL_IAM_ACCOUNT }}
|
CLOUD_SQL_IAM_ACCOUNT: ${{ secrets.CLOUD_SQL_IAM_ACCOUNT }}
|
||||||
APP_IAM_ACCOUNT: ${{ secrets.APP_IAM_ACCOUNT }}
|
APP_IAM_ACCOUNT: ${{ secrets.APP_IAM_ACCOUNT }}
|
||||||
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|
STATIC_IP_NAME: ${{ secrets.STATIC_IP_NAME }}
|
||||||
AFFINE_INDEXER_SEARCH_PROVIDER: ${{ secrets.AFFINE_INDEXER_SEARCH_PROVIDER }}
|
|
||||||
AFFINE_INDEXER_SEARCH_ENDPOINT: ${{ secrets.AFFINE_INDEXER_SEARCH_ENDPOINT }}
|
|
||||||
AFFINE_INDEXER_SEARCH_API_KEY: ${{ secrets.AFFINE_INDEXER_SEARCH_API_KEY }}
|
|
||||||
|
|
||||||
deploy-done:
|
deploy-done:
|
||||||
needs:
|
needs:
|
||||||
@@ -159,7 +156,7 @@ jobs:
|
|||||||
BLOCKSUITE_REPO_PATH: ${{ github.workspace }}/blocksuite
|
BLOCKSUITE_REPO_PATH: ${{ github.workspace }}/blocksuite
|
||||||
- name: Post Failed event to a Slack channel
|
- name: Post Failed event to a Slack channel
|
||||||
id: failed-slack
|
id: failed-slack
|
||||||
uses: slackapi/slack-github-action@v2.1.0
|
uses: slackapi/slack-github-action@v2.0.0
|
||||||
if: ${{ always() && contains(needs.*.result, 'failure') }}
|
if: ${{ always() && contains(needs.*.result, 'failure') }}
|
||||||
with:
|
with:
|
||||||
method: chat.postMessage
|
method: chat.postMessage
|
||||||
@@ -174,7 +171,7 @@ jobs:
|
|||||||
text: "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Backend deploy failed `${{ github.event.inputs.flavor }}`>"
|
text: "<${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|Backend deploy failed `${{ github.event.inputs.flavor }}`>"
|
||||||
- name: Post Cancel event to a Slack channel
|
- name: Post Cancel event to a Slack channel
|
||||||
id: cancel-slack
|
id: cancel-slack
|
||||||
uses: slackapi/slack-github-action@v2.1.0
|
uses: slackapi/slack-github-action@v2.0.0
|
||||||
if: ${{ always() && contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') }}
|
if: ${{ always() && contains(needs.*.result, 'cancelled') && !contains(needs.*.result, 'failure') }}
|
||||||
with:
|
with:
|
||||||
token: ${{ secrets.SLACK_BOT_TOKEN }}
|
token: ${{ secrets.SLACK_BOT_TOKEN }}
|
||||||
|
|||||||
@@ -252,7 +252,7 @@ jobs:
|
|||||||
shell: bash
|
shell: bash
|
||||||
# node_modules of nbstore is not needed for building, and it will make the build process out of memory
|
# node_modules of nbstore is not needed for building, and it will make the build process out of memory
|
||||||
run: |
|
run: |
|
||||||
rm -rf packages/frontend/apps/electron/node_modules/@affine/nbstore/node_modules/@blocksuite/affine/node_modules
|
rm -rf packages/frontend/apps/electron/node_modules/@affine/nbstore/node_modules/@blocksuite
|
||||||
rm -rf packages/frontend/apps/electron/node_modules/@affine/native/node_modules
|
rm -rf packages/frontend/apps/electron/node_modules/@affine/native/node_modules
|
||||||
|
|
||||||
- name: package
|
- name: package
|
||||||
|
|||||||
@@ -117,10 +117,31 @@ jobs:
|
|||||||
name: android
|
name: android
|
||||||
path: packages/frontend/apps/android/dist
|
path: packages/frontend/apps/android/dist
|
||||||
|
|
||||||
ios:
|
determine-ios-runner:
|
||||||
runs-on: ${{ github.ref_name == 'canary' && 'macos-latest' || 'blaze/macos-14' }}
|
runs-on: ubuntu-latest
|
||||||
needs:
|
needs:
|
||||||
- build-ios-web
|
- build-ios-web
|
||||||
|
outputs:
|
||||||
|
RUNNER: ${{ steps.runner.outputs.RUNNER }}
|
||||||
|
steps:
|
||||||
|
- name: Determine Runner
|
||||||
|
id: runner
|
||||||
|
# Randomly pick runner with 80% chance for blaze/macos-14 and 20% chance for namespace-profile-macos
|
||||||
|
# blaze/macos-14 is free but has limited concurrency
|
||||||
|
run: |
|
||||||
|
RANDOM_NUMBER=$(( $RANDOM % 100 + 1 ))
|
||||||
|
if [ $RANDOM_NUMBER -le 20 ]; then
|
||||||
|
echo "Selected namespace-profile-macos (20% probability)"
|
||||||
|
echo "RUNNER=namespace-profile-macos" >> $GITHUB_OUTPUT
|
||||||
|
else
|
||||||
|
echo "Selected blaze/macos-14 (80% probability)"
|
||||||
|
echo "RUNNER=blaze/macos-14" >> $GITHUB_OUTPUT
|
||||||
|
fi
|
||||||
|
|
||||||
|
ios:
|
||||||
|
runs-on: ${{ github.ref_name == 'canary' && 'macos-latest' || needs.determine-ios-runner.outputs.RUNNER }}
|
||||||
|
needs:
|
||||||
|
- determine-ios-runner
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
- name: Download mobile artifact
|
- name: Download mobile artifact
|
||||||
|
|||||||
@@ -38,5 +38,3 @@ packages/frontend/apps/ios/App/**
|
|||||||
tests/blocksuite/snapshots
|
tests/blocksuite/snapshots
|
||||||
blocksuite/docs/api/**
|
blocksuite/docs/api/**
|
||||||
packages/frontend/admin/src/config.json
|
packages/frontend/admin/src/config.json
|
||||||
**/test-docs.json
|
|
||||||
**/test-blocks.json
|
|
||||||
|
|||||||
Generated
+502
-529
File diff suppressed because it is too large
Load Diff
+7
-7
@@ -47,9 +47,9 @@ log = "0.4"
|
|||||||
loom = { version = "0.7", features = ["checkpoint"] }
|
loom = { version = "0.7", features = ["checkpoint"] }
|
||||||
mimalloc = "0.1"
|
mimalloc = "0.1"
|
||||||
nanoid = "0.4"
|
nanoid = "0.4"
|
||||||
napi = { version = "3.0.0-beta.3", features = ["async", "chrono_date", "error_anyhow", "napi9", "serde"] }
|
napi = { version = "3.0.0-alpha.31", features = ["async", "chrono_date", "error_anyhow", "napi9", "serde"] }
|
||||||
napi-build = { version = "2" }
|
napi-build = { version = "2" }
|
||||||
napi-derive = { version = "3.0.0-beta.3" }
|
napi-derive = { version = "3.0.0-alpha.28" }
|
||||||
nom = "8"
|
nom = "8"
|
||||||
notify = { version = "8", features = ["serde"] }
|
notify = { version = "8", features = ["serde"] }
|
||||||
objc2 = "0.6"
|
objc2 = "0.6"
|
||||||
@@ -57,7 +57,7 @@ objc2-foundation = "0.3"
|
|||||||
once_cell = "1"
|
once_cell = "1"
|
||||||
ordered-float = "5"
|
ordered-float = "5"
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
path-ext = "0.1.2"
|
path-ext = "0.1.1"
|
||||||
pdf-extract = { git = "https://github.com/toeverything/pdf-extract", branch = "darksky/improve-font-decoding" }
|
pdf-extract = { git = "https://github.com/toeverything/pdf-extract", branch = "darksky/improve-font-decoding" }
|
||||||
phf = { version = "0.11", features = ["macros"] }
|
phf = { version = "0.11", features = ["macros"] }
|
||||||
proptest = "1.3"
|
proptest = "1.3"
|
||||||
@@ -77,12 +77,12 @@ smol_str = "0.3"
|
|||||||
sqlx = { version = "0.8", default-features = false, features = ["chrono", "macros", "migrate", "runtime-tokio", "sqlite", "tls-rustls"] }
|
sqlx = { version = "0.8", default-features = false, features = ["chrono", "macros", "migrate", "runtime-tokio", "sqlite", "tls-rustls"] }
|
||||||
strum_macros = "0.27.0"
|
strum_macros = "0.27.0"
|
||||||
symphonia = { version = "0.5", features = ["all", "opt-simd"] }
|
symphonia = { version = "0.5", features = ["all", "opt-simd"] }
|
||||||
text-splitter = "0.27"
|
text-splitter = "0.25"
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
tiktoken-rs = "0.7"
|
tiktoken-rs = "0.6"
|
||||||
tokio = "1.45"
|
tokio = "1.37"
|
||||||
tree-sitter = { version = "0.25" }
|
tree-sitter = { version = "0.25" }
|
||||||
tree-sitter-c = { version = "0.24" }
|
tree-sitter-c = { version = "0.23" }
|
||||||
tree-sitter-c-sharp = { version = "0.23" }
|
tree-sitter-c-sharp = { version = "0.23" }
|
||||||
tree-sitter-cpp = { version = "0.23" }
|
tree-sitter-cpp = { version = "0.23" }
|
||||||
tree-sitter-go = { version = "0.23" }
|
tree-sitter-go = { version = "0.23" }
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ _Special thanks to [Blaze](https://runblaze.dev) for their support of this proje
|
|||||||
<a href="https://affine.pro/redirect/discord">Discord</a> |
|
<a href="https://affine.pro/redirect/discord">Discord</a> |
|
||||||
<a href="https://app.affine.pro">Live Demo</a> |
|
<a href="https://app.affine.pro">Live Demo</a> |
|
||||||
<a href="https://affine.pro/blog/">Blog</a> |
|
<a href="https://affine.pro/blog/">Blog</a> |
|
||||||
<a href="https://docs.affine.pro/">Documentation</a>
|
<a href="https://docs.affine.pro/docs/">Documentation</a>
|
||||||
</div>
|
</div>
|
||||||
<br/>
|
<br/>
|
||||||
|
|
||||||
@@ -89,7 +89,7 @@ Star us, and you will receive all release notifications from GitHub without any
|
|||||||
|
|
||||||
**Self-host & Shape your own AFFiNE**
|
**Self-host & Shape your own AFFiNE**
|
||||||
|
|
||||||
- You have the freedom to manage, self-host, fork and build your own AFFiNE. Plugin community and third-party blocks are coming soon. More tractions on [Blocksuite](https://blocksuite.io). Check there to learn how to [self-host AFFiNE](https://docs.affine.pro/self-host-affine).
|
- You have the freedom to manage, self-host, fork and build your own AFFiNE. Plugin community and third-party blocks are coming soon. More tractions on [Blocksuite](https://blocksuite.io). Check there to learn how to [self-host AFFiNE](https://docs.affine.pro/docs/self-host-affine).
|
||||||
|
|
||||||
## Acknowledgement
|
## Acknowledgement
|
||||||
|
|
||||||
@@ -191,9 +191,7 @@ We would like to express our gratitude to all the individuals who have already c
|
|||||||
|
|
||||||
## Self-Host
|
## Self-Host
|
||||||
|
|
||||||
Begin with Docker to deploy your own feature-rich, unrestricted version of AFFiNE. Our team is diligently updating to the latest version. For more information on how to self-host AFFiNE, please refer to our [documentation](https://docs.affine.pro/self-host-affine).
|
Begin with Docker to deploy your own feature-rich, unrestricted version of AFFiNE. Our team is diligently updating to the latest version. For more information on how to self-host AFFiNE, please refer to our [documentation](https://docs.affine.pro/docs/self-host-affine).
|
||||||
|
|
||||||
[](https://template.run.claw.cloud/?openapp=system-fastdeploy%3FtemplateName%3Daffine)
|
|
||||||
|
|
||||||
## Hiring
|
## Hiring
|
||||||
|
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
"@blocksuite/affine-block-divider": "workspace:*",
|
"@blocksuite/affine-block-divider": "workspace:*",
|
||||||
"@blocksuite/affine-block-edgeless-text": "workspace:*",
|
"@blocksuite/affine-block-edgeless-text": "workspace:*",
|
||||||
"@blocksuite/affine-block-embed": "workspace:*",
|
"@blocksuite/affine-block-embed": "workspace:*",
|
||||||
"@blocksuite/affine-block-embed-doc": "workspace:*",
|
|
||||||
"@blocksuite/affine-block-frame": "workspace:*",
|
"@blocksuite/affine-block-frame": "workspace:*",
|
||||||
"@blocksuite/affine-block-image": "workspace:*",
|
"@blocksuite/affine-block-image": "workspace:*",
|
||||||
"@blocksuite/affine-block-latex": "workspace:*",
|
"@blocksuite/affine-block-latex": "workspace:*",
|
||||||
@@ -33,7 +32,6 @@
|
|||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-ext-loader": "workspace:*",
|
"@blocksuite/affine-ext-loader": "workspace:*",
|
||||||
"@blocksuite/affine-foundation": "workspace:*",
|
"@blocksuite/affine-foundation": "workspace:*",
|
||||||
"@blocksuite/affine-fragment-adapter-panel": "workspace:*",
|
|
||||||
"@blocksuite/affine-fragment-doc-title": "workspace:*",
|
"@blocksuite/affine-fragment-doc-title": "workspace:*",
|
||||||
"@blocksuite/affine-fragment-frame-panel": "workspace:*",
|
"@blocksuite/affine-fragment-frame-panel": "workspace:*",
|
||||||
"@blocksuite/affine-fragment-outline": "workspace:*",
|
"@blocksuite/affine-fragment-outline": "workspace:*",
|
||||||
@@ -59,14 +57,11 @@
|
|||||||
"@blocksuite/affine-shared": "workspace:*",
|
"@blocksuite/affine-shared": "workspace:*",
|
||||||
"@blocksuite/affine-widget-drag-handle": "workspace:*",
|
"@blocksuite/affine-widget-drag-handle": "workspace:*",
|
||||||
"@blocksuite/affine-widget-edgeless-auto-connect": "workspace:*",
|
"@blocksuite/affine-widget-edgeless-auto-connect": "workspace:*",
|
||||||
"@blocksuite/affine-widget-edgeless-dragging-area": "workspace:*",
|
|
||||||
"@blocksuite/affine-widget-edgeless-selected-rect": "workspace:*",
|
|
||||||
"@blocksuite/affine-widget-edgeless-toolbar": "workspace:*",
|
"@blocksuite/affine-widget-edgeless-toolbar": "workspace:*",
|
||||||
"@blocksuite/affine-widget-edgeless-zoom-toolbar": "workspace:*",
|
"@blocksuite/affine-widget-edgeless-zoom-toolbar": "workspace:*",
|
||||||
"@blocksuite/affine-widget-frame-title": "workspace:*",
|
"@blocksuite/affine-widget-frame-title": "workspace:*",
|
||||||
"@blocksuite/affine-widget-keyboard-toolbar": "workspace:*",
|
"@blocksuite/affine-widget-keyboard-toolbar": "workspace:*",
|
||||||
"@blocksuite/affine-widget-linked-doc": "workspace:*",
|
"@blocksuite/affine-widget-linked-doc": "workspace:*",
|
||||||
"@blocksuite/affine-widget-note-slicer": "workspace:*",
|
|
||||||
"@blocksuite/affine-widget-page-dragging-area": "workspace:*",
|
"@blocksuite/affine-widget-page-dragging-area": "workspace:*",
|
||||||
"@blocksuite/affine-widget-remote-selection": "workspace:*",
|
"@blocksuite/affine-widget-remote-selection": "workspace:*",
|
||||||
"@blocksuite/affine-widget-scroll-anchoring": "workspace:*",
|
"@blocksuite/affine-widget-scroll-anchoring": "workspace:*",
|
||||||
@@ -126,9 +121,6 @@
|
|||||||
"./blocks/embed": "./src/blocks/embed/index.ts",
|
"./blocks/embed": "./src/blocks/embed/index.ts",
|
||||||
"./blocks/embed/store": "./src/blocks/embed/store.ts",
|
"./blocks/embed/store": "./src/blocks/embed/store.ts",
|
||||||
"./blocks/embed/view": "./src/blocks/embed/view.ts",
|
"./blocks/embed/view": "./src/blocks/embed/view.ts",
|
||||||
"./blocks/embed-doc": "./src/blocks/embed-doc/index.ts",
|
|
||||||
"./blocks/embed-doc/store": "./src/blocks/embed-doc/store.ts",
|
|
||||||
"./blocks/embed-doc/view": "./src/blocks/embed-doc/view.ts",
|
|
||||||
"./blocks/frame": "./src/blocks/frame/index.ts",
|
"./blocks/frame": "./src/blocks/frame/index.ts",
|
||||||
"./blocks/frame/store": "./src/blocks/frame/store.ts",
|
"./blocks/frame/store": "./src/blocks/frame/store.ts",
|
||||||
"./blocks/frame/view": "./src/blocks/frame/view.ts",
|
"./blocks/frame/view": "./src/blocks/frame/view.ts",
|
||||||
@@ -147,9 +139,7 @@
|
|||||||
"./blocks/paragraph": "./src/blocks/paragraph/index.ts",
|
"./blocks/paragraph": "./src/blocks/paragraph/index.ts",
|
||||||
"./blocks/paragraph/store": "./src/blocks/paragraph/store.ts",
|
"./blocks/paragraph/store": "./src/blocks/paragraph/store.ts",
|
||||||
"./blocks/paragraph/view": "./src/blocks/paragraph/view.ts",
|
"./blocks/paragraph/view": "./src/blocks/paragraph/view.ts",
|
||||||
"./blocks/root": "./src/blocks/root/index.ts",
|
"./blocks/root": "./src/blocks/root.ts",
|
||||||
"./blocks/root/store": "./src/blocks/root/store.ts",
|
|
||||||
"./blocks/root/view": "./src/blocks/root/view.ts",
|
|
||||||
"./blocks/surface": "./src/blocks/surface/index.ts",
|
"./blocks/surface": "./src/blocks/surface/index.ts",
|
||||||
"./blocks/surface/store": "./src/blocks/surface/store.ts",
|
"./blocks/surface/store": "./src/blocks/surface/store.ts",
|
||||||
"./blocks/surface/view": "./src/blocks/surface/view.ts",
|
"./blocks/surface/view": "./src/blocks/surface/view.ts",
|
||||||
@@ -182,8 +172,6 @@
|
|||||||
"./widgets/drag-handle/view": "./src/widgets/drag-handle/view.ts",
|
"./widgets/drag-handle/view": "./src/widgets/drag-handle/view.ts",
|
||||||
"./widgets/edgeless-auto-connect": "./src/widgets/edgeless-auto-connect/index.ts",
|
"./widgets/edgeless-auto-connect": "./src/widgets/edgeless-auto-connect/index.ts",
|
||||||
"./widgets/edgeless-auto-connect/view": "./src/widgets/edgeless-auto-connect/view.ts",
|
"./widgets/edgeless-auto-connect/view": "./src/widgets/edgeless-auto-connect/view.ts",
|
||||||
"./widgets/edgeless-dragging-area": "./src/widgets/edgeless-dragging-area/index.ts",
|
|
||||||
"./widgets/edgeless-dragging-area/view": "./src/widgets/edgeless-dragging-area/view.ts",
|
|
||||||
"./widgets/edgeless-toolbar": "./src/widgets/edgeless-toolbar/index.ts",
|
"./widgets/edgeless-toolbar": "./src/widgets/edgeless-toolbar/index.ts",
|
||||||
"./widgets/edgeless-toolbar/view": "./src/widgets/edgeless-toolbar/view.ts",
|
"./widgets/edgeless-toolbar/view": "./src/widgets/edgeless-toolbar/view.ts",
|
||||||
"./widgets/frame-title": "./src/widgets/frame-title/index.ts",
|
"./widgets/frame-title": "./src/widgets/frame-title/index.ts",
|
||||||
@@ -204,14 +192,9 @@
|
|||||||
"./widgets/viewport-overlay/view": "./src/widgets/viewport-overlay/view.ts",
|
"./widgets/viewport-overlay/view": "./src/widgets/viewport-overlay/view.ts",
|
||||||
"./widgets/page-dragging-area": "./src/widgets/page-dragging-area/index.ts",
|
"./widgets/page-dragging-area": "./src/widgets/page-dragging-area/index.ts",
|
||||||
"./widgets/page-dragging-area/view": "./src/widgets/page-dragging-area/view.ts",
|
"./widgets/page-dragging-area/view": "./src/widgets/page-dragging-area/view.ts",
|
||||||
"./fragments/doc-title": "./src/fragments/doc-title/index.ts",
|
"./fragments/doc-title": "./src/fragments/doc-title.ts",
|
||||||
"./fragments/doc-title/view": "./src/fragments/doc-title/view.ts",
|
"./fragments/frame-panel": "./src/fragments/frame-panel.ts",
|
||||||
"./fragments/frame-panel": "./src/fragments/frame-panel/index.ts",
|
"./fragments/outline": "./src/fragments/outline.ts",
|
||||||
"./fragments/frame-panel/view": "./src/fragments/frame-panel/view.ts",
|
|
||||||
"./fragments/outline": "./src/fragments/outline/index.ts",
|
|
||||||
"./fragments/outline/view": "./src/fragments/outline/view.ts",
|
|
||||||
"./fragments/adapter-panel": "./src/fragments/adapter-panel/index.ts",
|
|
||||||
"./fragments/adapter-panel/view": "./src/fragments/adapter-panel/view.ts",
|
|
||||||
"./gfx/text": "./src/gfx/text/index.ts",
|
"./gfx/text": "./src/gfx/text/index.ts",
|
||||||
"./gfx/text/store": "./src/gfx/text/store.ts",
|
"./gfx/text/store": "./src/gfx/text/store.ts",
|
||||||
"./gfx/text/view": "./src/gfx/text/view.ts",
|
"./gfx/text/view": "./src/gfx/text/view.ts",
|
||||||
@@ -266,7 +249,6 @@
|
|||||||
"./components/toolbar": "./src/components/toolbar.ts",
|
"./components/toolbar": "./src/components/toolbar.ts",
|
||||||
"./components/view-dropdown-menu": "./src/components/view-dropdown-menu.ts",
|
"./components/view-dropdown-menu": "./src/components/view-dropdown-menu.ts",
|
||||||
"./components/tooltip-content-with-shortcut": "./src/components/tooltip-content-with-shortcut.ts",
|
"./components/tooltip-content-with-shortcut": "./src/components/tooltip-content-with-shortcut.ts",
|
||||||
"./components/resource": "./src/components/resource.ts",
|
|
||||||
"./rich-text": "./src/rich-text/index.ts",
|
"./rich-text": "./src/rich-text/index.ts",
|
||||||
"./rich-text/effects": "./src/rich-text/effects.ts",
|
"./rich-text/effects": "./src/rich-text/effects.ts",
|
||||||
"./shared/adapters": "./src/shared/adapters.ts",
|
"./shared/adapters": "./src/shared/adapters.ts",
|
||||||
@@ -282,9 +264,7 @@
|
|||||||
"./model": "./src/model/index.ts",
|
"./model": "./src/model/index.ts",
|
||||||
"./sync": "./src/sync/index.ts",
|
"./sync": "./src/sync/index.ts",
|
||||||
"./extensions/store": "./src/extensions/store.ts",
|
"./extensions/store": "./src/extensions/store.ts",
|
||||||
"./extensions/view": "./src/extensions/view.ts",
|
"./extensions/view": "./src/extensions/view.ts"
|
||||||
"./foundation/store": "./src/foundation/store.ts",
|
|
||||||
"./foundation/view": "./src/foundation/view.ts"
|
|
||||||
},
|
},
|
||||||
"files": [
|
"files": [
|
||||||
"src",
|
"src",
|
||||||
@@ -295,7 +275,6 @@
|
|||||||
"version": "0.21.0",
|
"version": "0.21.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@vanilla-extract/vite-plugin": "^5.0.0",
|
"@vanilla-extract/vite-plugin": "^5.0.0",
|
||||||
"msw": "^2.8.4",
|
"vitest": "3.1.1"
|
||||||
"vitest": "3.1.3"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2360,65 +2360,6 @@ describe('html to snapshot', () => {
|
|||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should preserve space in p', async () => {
|
|
||||||
const html = template(
|
|
||||||
`<p>A <b>bold text</b> followed by a <i>italic text</i></p>`
|
|
||||||
);
|
|
||||||
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'A ',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'bold text',
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: ' followed by a ',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'italic text',
|
|
||||||
attributes: {
|
|
||||||
italic: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('span nested in p', async () => {
|
test('span nested in p', async () => {
|
||||||
const html = template(
|
const html = template(
|
||||||
`<p><span>aaa</span><span>bbb</span><span>ccc</span></p>`
|
`<p><span>aaa</span><span>bbb</span><span>ccc</span></p>`
|
||||||
@@ -2697,335 +2638,4 @@ describe('html to snapshot', () => {
|
|||||||
});
|
});
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('block level element in b should not be treated as inline', async () => {
|
|
||||||
const html = template(`<b><p><span>aaa</span></p></b>`);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('strong element', () => {
|
|
||||||
test('should not be bold when font-weight is normal', async () => {
|
|
||||||
const html = template(`<span style="font-weight: normal;">aaa</span>`);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should be bold when font-weight is bold or 500-900 ', async () => {
|
|
||||||
const html = template(
|
|
||||||
`<p><span style="font-weight: bold;">aaa</span><span style="font-weight: 100;">aaa</span><span style="font-weight: 500;">bbb</span><span style="font-weight: 200;">bbb</span><span style="font-weight: 600;">ccc</span><span style="font-weight: 300;">ccc</span><span style="font-weight: 700;">ddd</span></p>`
|
|
||||||
);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
insert: 'ccc',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'ccc',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
insert: 'ddd',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should be italic when tag is i or em or span with style font-style: italic', async () => {
|
|
||||||
const html = template(
|
|
||||||
`<p><i>aaa</i><span>aaa</span><em>bbb</em><span>bbb</span><span style="font-style: italic;">ccc</span></p>`
|
|
||||||
);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
italic: true,
|
|
||||||
},
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
italic: true,
|
|
||||||
},
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
italic: true,
|
|
||||||
},
|
|
||||||
insert: 'ccc',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should be underline when tag is u or span with style text-decoration: underline', async () => {
|
|
||||||
const html = template(
|
|
||||||
`<p><u>aaa</u><span>aaa</span><span style="text-decoration: underline;">bbb</span></p>`
|
|
||||||
);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
underline: true,
|
|
||||||
},
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
underline: true,
|
|
||||||
},
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('should be strike when tag is del or span with style text-decoration: line-through', async () => {
|
|
||||||
const html = template(
|
|
||||||
`<p><del>aaa</del><span>aaa</span><span style="text-decoration: line-through;">bbb</span></p>`
|
|
||||||
);
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
strike: true,
|
|
||||||
},
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'aaa',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
attributes: {
|
|
||||||
strike: true,
|
|
||||||
},
|
|
||||||
insert: 'bbb',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const htmlAdapter = new HtmlAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await htmlAdapter.toBlockSnapshot({
|
|
||||||
file: html,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,9 +4,6 @@ import {
|
|||||||
TableModelFlavour,
|
TableModelFlavour,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
CalloutAdmonitionType,
|
|
||||||
CalloutExportStyle,
|
|
||||||
calloutMarkdownExportMiddleware,
|
|
||||||
embedSyncedDocMiddleware,
|
embedSyncedDocMiddleware,
|
||||||
MarkdownAdapter,
|
MarkdownAdapter,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
@@ -2451,290 +2448,6 @@ World!
|
|||||||
});
|
});
|
||||||
expect(target.file).toBe(markdown);
|
expect(target.file).toBe(markdown);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('callout', () => {
|
|
||||||
test('without export middleware', async () => {
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:vu6SK6WJpW',
|
|
||||||
flavour: 'affine:page',
|
|
||||||
props: {
|
|
||||||
title: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:Tk4gSPocAt',
|
|
||||||
flavour: 'affine:surface',
|
|
||||||
props: {
|
|
||||||
elements: {},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:WfnS5ZDCJT',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '💡',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [{ insert: 'First callout' }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxadvdv',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{ insert: 'Warning second callout without emoji' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [{ insert: 'Text in second callout' }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const markdown = `> \\[!💡]
|
|
||||||
>
|
|
||||||
> First callout
|
|
||||||
|
|
||||||
> \\[!]
|
|
||||||
>
|
|
||||||
> Warning second callout without emoji
|
|
||||||
>
|
|
||||||
> Text in second callout
|
|
||||||
`;
|
|
||||||
|
|
||||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
|
||||||
const target = await mdAdapter.fromBlockSnapshot({
|
|
||||||
snapshot: blockSnapshot,
|
|
||||||
});
|
|
||||||
expect(target.file).toBe(markdown);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('with export middleware', async () => {
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:vu6SK6WJpW',
|
|
||||||
flavour: 'affine:page',
|
|
||||||
props: {
|
|
||||||
title: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:Tk4gSPocAt',
|
|
||||||
flavour: 'affine:surface',
|
|
||||||
props: {
|
|
||||||
elements: {},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:WfnS5ZDCJT',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '💡',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{ insert: 'Callout that does not have a title' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxadvdv',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert:
|
|
||||||
'Warning callout with custom title and multiple paragraphs',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [{ insert: 'Text in second callout' }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '💡',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'block:8hOLxad5Fv',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{ insert: 'details' },
|
|
||||||
{ insert: ' ' },
|
|
||||||
{ insert: '\nText in details callout with new line' },
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const markdown = `::: info
|
|
||||||
|
|
||||||
Callout that does not have a title
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: warning callout with custom title and multiple paragraphs
|
|
||||||
|
|
||||||
Text in second callout
|
|
||||||
|
|
||||||
:::
|
|
||||||
|
|
||||||
::: details
|
|
||||||
|
|
||||||
Text in details callout with new line
|
|
||||||
|
|
||||||
:::
|
|
||||||
`;
|
|
||||||
|
|
||||||
const mdAdapter = new MarkdownAdapter(
|
|
||||||
createJob([
|
|
||||||
calloutMarkdownExportMiddleware({
|
|
||||||
style: CalloutExportStyle.Admonitions,
|
|
||||||
admonitionType: CalloutAdmonitionType.Info,
|
|
||||||
}),
|
|
||||||
]),
|
|
||||||
provider
|
|
||||||
);
|
|
||||||
const target = await mdAdapter.fromBlockSnapshot({
|
|
||||||
snapshot: blockSnapshot,
|
|
||||||
});
|
|
||||||
expect(target.file).toBe(markdown);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('markdown to snapshot', () => {
|
describe('markdown to snapshot', () => {
|
||||||
@@ -3875,7 +3588,7 @@ bbb
|
|||||||
props: {
|
props: {
|
||||||
xywh: '[0,0,800,95]',
|
xywh: '[0,0,800,95]',
|
||||||
background: {
|
background: {
|
||||||
dark: '#252525',
|
dark: '#000000',
|
||||||
light: '#ffffff',
|
light: '#ffffff',
|
||||||
},
|
},
|
||||||
index: 'a0',
|
index: 'a0',
|
||||||
@@ -4393,61 +4106,6 @@ hhh
|
|||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[2]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'h6',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'Sources',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
collapsed: true,
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[3]',
|
|
||||||
flavour: 'affine:bookmark',
|
|
||||||
props: {
|
|
||||||
style: 'citation',
|
|
||||||
url,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
icon: favicon,
|
|
||||||
footnoteIdentifier: '1',
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[4]',
|
|
||||||
flavour: 'affine:embed-linked-doc',
|
|
||||||
props: {
|
|
||||||
style: 'citation',
|
|
||||||
pageId: 'deadbeef',
|
|
||||||
footnoteIdentifier: '2',
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[5]',
|
|
||||||
flavour: 'affine:attachment',
|
|
||||||
props: {
|
|
||||||
name: 'test.txt',
|
|
||||||
sourceId: 'abcdefg',
|
|
||||||
footnoteIdentifier: '3',
|
|
||||||
style: 'citation',
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -4472,101 +4130,6 @@ hhh
|
|||||||
});
|
});
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should handle footnote reference with url prefix', async () => {
|
|
||||||
const blockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'https://example.com',
|
|
||||||
attributes: {
|
|
||||||
link: 'https://example.com',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: ' ',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: ' ',
|
|
||||||
attributes: {
|
|
||||||
footnote: {
|
|
||||||
label: '1',
|
|
||||||
reference: {
|
|
||||||
type: 'url',
|
|
||||||
url,
|
|
||||||
favicon,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[2]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'h6',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'Sources',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
collapsed: true,
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[3]',
|
|
||||||
flavour: 'affine:bookmark',
|
|
||||||
props: {
|
|
||||||
style: 'citation',
|
|
||||||
url,
|
|
||||||
title,
|
|
||||||
description,
|
|
||||||
icon: favicon,
|
|
||||||
footnoteIdentifier: '1',
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const markdown = `https://example.com[^1]\n\n[^1]: {"type":"url","url":"${url}","favicon":"${favicon}","title":"${title}","description":"${description}"}\n`;
|
|
||||||
|
|
||||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
|
||||||
file: markdown,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('should not wrap url with angle brackets if it is not a url', async () => {
|
test('should not wrap url with angle brackets if it is not a url', async () => {
|
||||||
@@ -4619,62 +4182,4 @@ hhh
|
|||||||
});
|
});
|
||||||
expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot);
|
expect(nanoidReplacement(rawSliceSnapshot!)).toEqual(sliceSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('callout', () => {
|
|
||||||
const calloutBlockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:callout',
|
|
||||||
props: {
|
|
||||||
emoji: '💬',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[2]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [{ insert: 'This is a callout' }],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
test('callout start with escape character', async () => {
|
|
||||||
const markdown = '> \\[!💬]\n> This is a callout';
|
|
||||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
|
||||||
file: markdown,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(calloutBlockSnapshot);
|
|
||||||
});
|
|
||||||
|
|
||||||
test('callout start without escape character', async () => {
|
|
||||||
const markdown = '> [!💬]\n> This is a callout';
|
|
||||||
const mdAdapter = new MarkdownAdapter(createJob(), provider);
|
|
||||||
const rawBlockSnapshot = await mdAdapter.toBlockSnapshot({
|
|
||||||
file: markdown,
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(calloutBlockSnapshot);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,14 +1,11 @@
|
|||||||
import { DefaultTheme, NoteDisplayMode } from '@blocksuite/affine-model';
|
import { DefaultTheme, NoteDisplayMode } from '@blocksuite/affine-model';
|
||||||
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
import { NotionHtmlAdapter } from '@blocksuite/affine-shared/adapters';
|
||||||
import { DEFAULT_IMAGE_PROXY_ENDPOINT } from '@blocksuite/affine-shared/consts';
|
|
||||||
import {
|
import {
|
||||||
AssetsManager,
|
AssetsManager,
|
||||||
type BlockSnapshot,
|
type BlockSnapshot,
|
||||||
MemoryBlobCRUD,
|
MemoryBlobCRUD,
|
||||||
} from '@blocksuite/store';
|
} from '@blocksuite/store';
|
||||||
import { http, HttpResponse } from 'msw';
|
import { describe, expect, test } from 'vitest';
|
||||||
import { setupServer } from 'msw/node';
|
|
||||||
import { afterAll, afterEach, beforeAll, describe, expect, test } from 'vitest';
|
|
||||||
|
|
||||||
import { createJob } from '../utils/create-job.js';
|
import { createJob } from '../utils/create-job.js';
|
||||||
import { getProvider } from '../utils/get-provider.js';
|
import { getProvider } from '../utils/get-provider.js';
|
||||||
@@ -1198,71 +1195,43 @@ describe('notion html to snapshot', () => {
|
|||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('image', () => {
|
test('image', async () => {
|
||||||
const originalUrl =
|
const html = `<div class="page-body">
|
||||||
'https://raw.githubusercontent.com/toeverything/blocksuite/master/assets/logo.svg';
|
<figure id="ed3d2ae9-62f5-433a-9049-9ddbd1c81ac5" class="image"><a
|
||||||
|
href="https://raw.githubusercontent.com/toeverything/blocksuite/master/assets/logo.svg"><img src="https://raw.githubusercontent.com/toeverything/blocksuite/master/assets/logo.svg" /></a>
|
||||||
|
</figure>
|
||||||
|
</div>`;
|
||||||
|
|
||||||
const imageProxy = DEFAULT_IMAGE_PROXY_ENDPOINT;
|
const blockSnapshot: BlockSnapshot = {
|
||||||
const imageUrl = `${imageProxy}?url=${encodeURIComponent(originalUrl)}`;
|
type: 'block',
|
||||||
|
id: 'matchesReplaceMap[0]',
|
||||||
// Mock the image request
|
flavour: 'affine:note',
|
||||||
const imageRequestHandlers = [
|
props: {
|
||||||
http.get(imageUrl.toString(), async () => {
|
xywh: '[0,0,800,95]',
|
||||||
// Return a mock image blob
|
background: DefaultTheme.noteBackgrounColor,
|
||||||
const mockImageBlob = new Blob(['mock image data'], {
|
index: 'a0',
|
||||||
type: 'image/svg+xml',
|
hidden: false,
|
||||||
});
|
displayMode: NoteDisplayMode.DocAndEdgeless,
|
||||||
return new HttpResponse(mockImageBlob, {
|
},
|
||||||
headers: {
|
children: [
|
||||||
'Content-Type': 'image/svg+xml',
|
{
|
||||||
|
type: 'block',
|
||||||
|
id: 'matchesReplaceMap[1]',
|
||||||
|
flavour: 'affine:image',
|
||||||
|
props: {
|
||||||
|
sourceId: 'matchesReplaceMap[2]',
|
||||||
},
|
},
|
||||||
});
|
children: [],
|
||||||
}),
|
|
||||||
];
|
|
||||||
|
|
||||||
const server = setupServer(...imageRequestHandlers);
|
|
||||||
beforeAll(() => server.listen({ onUnhandledRequest: 'error' }));
|
|
||||||
afterAll(() => server.close());
|
|
||||||
afterEach(() => server.resetHandlers());
|
|
||||||
|
|
||||||
test('network image resource', async () => {
|
|
||||||
const html = `<div class="page-body">
|
|
||||||
<figure id="ed3d2ae9-62f5-433a-9049-9ddbd1c81ac5" class="image"><a
|
|
||||||
href="${originalUrl}"><img src="${originalUrl}" /></a>
|
|
||||||
</figure>
|
|
||||||
</div>`;
|
|
||||||
|
|
||||||
const blockSnapshot: BlockSnapshot = {
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: NoteDisplayMode.DocAndEdgeless,
|
|
||||||
},
|
},
|
||||||
children: [
|
],
|
||||||
{
|
};
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:image',
|
|
||||||
props: {
|
|
||||||
sourceId: 'matchesReplaceMap[2]',
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
const adapter = new NotionHtmlAdapter(createJob(), provider);
|
const adapter = new NotionHtmlAdapter(createJob(), provider);
|
||||||
const rawBlockSnapshot = await adapter.toBlockSnapshot({
|
const rawBlockSnapshot = await adapter.toBlockSnapshot({
|
||||||
file: html,
|
file: html,
|
||||||
assets: new AssetsManager({ blob: new MemoryBlobCRUD() }),
|
assets: new AssetsManager({ blob: new MemoryBlobCRUD() }),
|
||||||
});
|
|
||||||
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
|
||||||
});
|
});
|
||||||
|
expect(nanoidReplacement(rawBlockSnapshot)).toEqual(blockSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('bookmark', async () => {
|
test('bookmark', async () => {
|
||||||
|
|||||||
@@ -106,65 +106,4 @@ describe('notion-text to snapshot', () => {
|
|||||||
});
|
});
|
||||||
expect(nanoidReplacement(target!)).toEqual(sliceSnapshot);
|
expect(nanoidReplacement(target!)).toEqual(sliceSnapshot);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('notion text with empty styles array', () => {
|
|
||||||
const notionText =
|
|
||||||
'{"blockType":"text","editing":[["a "],["bold text",[["b"]]],[" hello world"]],"selection":{"startIndex":0,"endIndex":23},"action":"copy"}';
|
|
||||||
|
|
||||||
const sliceSnapshot: SliceSnapshot = {
|
|
||||||
type: 'slice',
|
|
||||||
content: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[0]',
|
|
||||||
flavour: 'affine:note',
|
|
||||||
props: {
|
|
||||||
xywh: '[0,0,800,95]',
|
|
||||||
background: DefaultTheme.noteBackgrounColor,
|
|
||||||
index: 'a0',
|
|
||||||
hidden: false,
|
|
||||||
displayMode: 'both',
|
|
||||||
},
|
|
||||||
children: [
|
|
||||||
{
|
|
||||||
type: 'block',
|
|
||||||
id: 'matchesReplaceMap[1]',
|
|
||||||
flavour: 'affine:paragraph',
|
|
||||||
props: {
|
|
||||||
type: 'text',
|
|
||||||
text: {
|
|
||||||
'$blocksuite:internal:text$': true,
|
|
||||||
delta: [
|
|
||||||
{
|
|
||||||
insert: 'a ',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: 'bold text',
|
|
||||||
attributes: {
|
|
||||||
bold: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
insert: ' hello world',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
children: [],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
},
|
|
||||||
],
|
|
||||||
workspaceId: '',
|
|
||||||
pageId: '',
|
|
||||||
};
|
|
||||||
|
|
||||||
const ntAdapter = new NotionTextAdapter(createJob(), provider);
|
|
||||||
const target = ntAdapter.toSliceSnapshot({
|
|
||||||
file: notionText,
|
|
||||||
workspaceId: '',
|
|
||||||
pageId: '',
|
|
||||||
});
|
|
||||||
expect(nanoidReplacement(target!)).toEqual(sliceSnapshot);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,65 @@
|
|||||||
|
import {
|
||||||
|
HtmlInlineToDeltaAdapterExtensions,
|
||||||
|
InlineDeltaToHtmlAdapterExtensions,
|
||||||
|
InlineDeltaToMarkdownAdapterExtensions,
|
||||||
|
MarkdownInlineToDeltaAdapterExtensions,
|
||||||
|
NotionHtmlInlineToDeltaAdapterExtensions,
|
||||||
|
} from '@blocksuite/affine-inline-preset';
|
||||||
|
import {
|
||||||
|
AttachmentAdapterFactoryExtension,
|
||||||
|
HtmlAdapterFactoryExtension,
|
||||||
|
ImageAdapterFactoryExtension,
|
||||||
|
MarkdownAdapterFactoryExtension,
|
||||||
|
MixTextAdapterFactoryExtension,
|
||||||
|
NotionHtmlAdapterFactoryExtension,
|
||||||
|
NotionTextAdapterFactoryExtension,
|
||||||
|
PlainTextAdapterFactoryExtension,
|
||||||
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
import { defaultBlockHtmlAdapterMatchers } from './html/block-matcher';
|
||||||
|
import { defaultBlockMarkdownAdapterMatchers } from './markdown/block-matcher';
|
||||||
|
import { defaultMarkdownPreprocessors } from './markdown/preprocessor';
|
||||||
|
import { defaultBlockNotionHtmlAdapterMatchers } from './notion-html/block-matcher';
|
||||||
|
import { defaultBlockPlainTextAdapterMatchers } from './plain-text/block-matcher';
|
||||||
|
|
||||||
|
export function getAdapterFactoryExtensions(): ExtensionType[] {
|
||||||
|
return [
|
||||||
|
AttachmentAdapterFactoryExtension,
|
||||||
|
ImageAdapterFactoryExtension,
|
||||||
|
MarkdownAdapterFactoryExtension,
|
||||||
|
PlainTextAdapterFactoryExtension,
|
||||||
|
HtmlAdapterFactoryExtension,
|
||||||
|
NotionTextAdapterFactoryExtension,
|
||||||
|
NotionHtmlAdapterFactoryExtension,
|
||||||
|
MixTextAdapterFactoryExtension,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getHtmlAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [
|
||||||
|
...HtmlInlineToDeltaAdapterExtensions,
|
||||||
|
...defaultBlockHtmlAdapterMatchers,
|
||||||
|
...InlineDeltaToHtmlAdapterExtensions,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getMarkdownAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [
|
||||||
|
...MarkdownInlineToDeltaAdapterExtensions,
|
||||||
|
...defaultBlockMarkdownAdapterMatchers,
|
||||||
|
...InlineDeltaToMarkdownAdapterExtensions,
|
||||||
|
...defaultMarkdownPreprocessors,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getNotionHtmlAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [
|
||||||
|
...NotionHtmlInlineToDeltaAdapterExtensions,
|
||||||
|
...defaultBlockNotionHtmlAdapterMatchers,
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getPlainTextAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [...defaultBlockPlainTextAdapterMatchers];
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
import { BookmarkBlockHtmlAdapterExtension } from '@blocksuite/affine-block-bookmark';
|
||||||
|
import { CodeBlockHtmlAdapterExtension } from '@blocksuite/affine-block-code';
|
||||||
|
import { DatabaseBlockHtmlAdapterExtension } from '@blocksuite/affine-block-database';
|
||||||
|
import { DividerBlockHtmlAdapterExtension } from '@blocksuite/affine-block-divider';
|
||||||
|
import {
|
||||||
|
EmbedFigmaBlockHtmlAdapterExtension,
|
||||||
|
EmbedGithubBlockHtmlAdapterExtension,
|
||||||
|
EmbedIframeBlockHtmlAdapterExtension,
|
||||||
|
EmbedLinkedDocHtmlAdapterExtension,
|
||||||
|
EmbedLoomBlockHtmlAdapterExtension,
|
||||||
|
EmbedSyncedDocBlockHtmlAdapterExtension,
|
||||||
|
EmbedYoutubeBlockHtmlAdapterExtension,
|
||||||
|
} from '@blocksuite/affine-block-embed';
|
||||||
|
import { ImageBlockHtmlAdapterExtension } from '@blocksuite/affine-block-image';
|
||||||
|
import { ListBlockHtmlAdapterExtension } from '@blocksuite/affine-block-list';
|
||||||
|
import { ParagraphBlockHtmlAdapterExtension } from '@blocksuite/affine-block-paragraph';
|
||||||
|
import { RootBlockHtmlAdapterExtension } from '@blocksuite/affine-block-root';
|
||||||
|
import { TableBlockHtmlAdapterExtension } from '@blocksuite/affine-block-table';
|
||||||
|
|
||||||
|
export const defaultBlockHtmlAdapterMatchers = [
|
||||||
|
ListBlockHtmlAdapterExtension,
|
||||||
|
ParagraphBlockHtmlAdapterExtension,
|
||||||
|
CodeBlockHtmlAdapterExtension,
|
||||||
|
DividerBlockHtmlAdapterExtension,
|
||||||
|
ImageBlockHtmlAdapterExtension,
|
||||||
|
RootBlockHtmlAdapterExtension,
|
||||||
|
EmbedYoutubeBlockHtmlAdapterExtension,
|
||||||
|
EmbedFigmaBlockHtmlAdapterExtension,
|
||||||
|
EmbedLoomBlockHtmlAdapterExtension,
|
||||||
|
EmbedGithubBlockHtmlAdapterExtension,
|
||||||
|
EmbedIframeBlockHtmlAdapterExtension,
|
||||||
|
BookmarkBlockHtmlAdapterExtension,
|
||||||
|
DatabaseBlockHtmlAdapterExtension,
|
||||||
|
TableBlockHtmlAdapterExtension,
|
||||||
|
EmbedLinkedDocHtmlAdapterExtension,
|
||||||
|
EmbedSyncedDocBlockHtmlAdapterExtension,
|
||||||
|
];
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export * from './extension.js';
|
||||||
|
export * from './html/block-matcher.js';
|
||||||
|
export * from './markdown/block-matcher.js';
|
||||||
|
export * from './markdown/preprocessor.js';
|
||||||
|
export * from './notion-html/block-matcher.js';
|
||||||
|
export * from './plain-text/block-matcher.js';
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { AttachmentBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-attachment';
|
||||||
|
import { BookmarkBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-bookmark';
|
||||||
|
import { CodeBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-code';
|
||||||
|
import { DatabaseBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-database';
|
||||||
|
import { DividerBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-divider';
|
||||||
|
import {
|
||||||
|
EmbedFigmaMarkdownAdapterExtension,
|
||||||
|
EmbedGithubMarkdownAdapterExtension,
|
||||||
|
EmbedIframeBlockMarkdownAdapterExtension,
|
||||||
|
EmbedLinkedDocMarkdownAdapterExtension,
|
||||||
|
EmbedLoomMarkdownAdapterExtension,
|
||||||
|
EmbedSyncedDocMarkdownAdapterExtension,
|
||||||
|
EmbedYoutubeMarkdownAdapterExtension,
|
||||||
|
} from '@blocksuite/affine-block-embed';
|
||||||
|
import { ImageBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-image';
|
||||||
|
import { LatexBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-latex';
|
||||||
|
import { ListBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-list';
|
||||||
|
import { DocNoteBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-note';
|
||||||
|
import { ParagraphBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-paragraph';
|
||||||
|
import { RootBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-root';
|
||||||
|
import { TableBlockMarkdownAdapterExtension } from '@blocksuite/affine-block-table';
|
||||||
|
|
||||||
|
export const defaultBlockMarkdownAdapterMatchers = [
|
||||||
|
RootBlockMarkdownAdapterExtension,
|
||||||
|
DocNoteBlockMarkdownAdapterExtension,
|
||||||
|
EmbedFigmaMarkdownAdapterExtension,
|
||||||
|
EmbedGithubMarkdownAdapterExtension,
|
||||||
|
EmbedLinkedDocMarkdownAdapterExtension,
|
||||||
|
EmbedLoomMarkdownAdapterExtension,
|
||||||
|
EmbedSyncedDocMarkdownAdapterExtension,
|
||||||
|
EmbedYoutubeMarkdownAdapterExtension,
|
||||||
|
EmbedIframeBlockMarkdownAdapterExtension,
|
||||||
|
ListBlockMarkdownAdapterExtension,
|
||||||
|
ParagraphBlockMarkdownAdapterExtension,
|
||||||
|
BookmarkBlockMarkdownAdapterExtension,
|
||||||
|
CodeBlockMarkdownAdapterExtension,
|
||||||
|
DatabaseBlockMarkdownAdapterExtension,
|
||||||
|
TableBlockMarkdownAdapterExtension,
|
||||||
|
DividerBlockMarkdownAdapterExtension,
|
||||||
|
ImageBlockMarkdownAdapterExtension,
|
||||||
|
LatexBlockMarkdownAdapterExtension,
|
||||||
|
AttachmentBlockMarkdownAdapterExtension,
|
||||||
|
];
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
import { BookmarkBlockMarkdownPreprocessorExtension } from '@blocksuite/affine-block-bookmark';
|
||||||
|
import { CodeMarkdownPreprocessorExtension } from '@blocksuite/affine-block-code';
|
||||||
|
import { LatexMarkdownPreprocessorExtension } from '@blocksuite/affine-block-latex';
|
||||||
|
|
||||||
|
export const defaultMarkdownPreprocessors = [
|
||||||
|
LatexMarkdownPreprocessorExtension,
|
||||||
|
CodeMarkdownPreprocessorExtension,
|
||||||
|
BookmarkBlockMarkdownPreprocessorExtension,
|
||||||
|
];
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { AttachmentBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-attachment';
|
||||||
|
import { BookmarkBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-bookmark';
|
||||||
|
import { CodeBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-code';
|
||||||
|
import { DatabaseBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-database';
|
||||||
|
import { DividerBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-divider';
|
||||||
|
import {
|
||||||
|
EmbedFigmaBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedGithubBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedLoomBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedYoutubeBlockNotionHtmlAdapterExtension,
|
||||||
|
} from '@blocksuite/affine-block-embed';
|
||||||
|
import { ImageBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-image';
|
||||||
|
import { LatexBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-latex';
|
||||||
|
import { ListBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-list';
|
||||||
|
import { ParagraphBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-paragraph';
|
||||||
|
import { RootBlockNotionHtmlAdapterExtension } from '@blocksuite/affine-block-root';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
export const defaultBlockNotionHtmlAdapterMatchers: ExtensionType[] = [
|
||||||
|
ListBlockNotionHtmlAdapterExtension,
|
||||||
|
ParagraphBlockNotionHtmlAdapterExtension,
|
||||||
|
CodeBlockNotionHtmlAdapterExtension,
|
||||||
|
DividerBlockNotionHtmlAdapterExtension,
|
||||||
|
ImageBlockNotionHtmlAdapterExtension,
|
||||||
|
RootBlockNotionHtmlAdapterExtension,
|
||||||
|
BookmarkBlockNotionHtmlAdapterExtension,
|
||||||
|
DatabaseBlockNotionHtmlAdapterExtension,
|
||||||
|
LatexBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedYoutubeBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedFigmaBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedGithubBlockNotionHtmlAdapterExtension,
|
||||||
|
EmbedLoomBlockNotionHtmlAdapterExtension,
|
||||||
|
AttachmentBlockNotionHtmlAdapterExtension,
|
||||||
|
];
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import { BookmarkBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-bookmark';
|
||||||
|
import { CodeBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-code';
|
||||||
|
import { DatabaseBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-database';
|
||||||
|
import { DividerBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-divider';
|
||||||
|
import {
|
||||||
|
EmbedFigmaBlockPlainTextAdapterExtension,
|
||||||
|
EmbedGithubBlockPlainTextAdapterExtension,
|
||||||
|
EmbedIframeBlockPlainTextAdapterExtension,
|
||||||
|
EmbedLinkedDocBlockPlainTextAdapterExtension,
|
||||||
|
EmbedLoomBlockPlainTextAdapterExtension,
|
||||||
|
EmbedSyncedDocBlockPlainTextAdapterExtension,
|
||||||
|
EmbedYoutubeBlockPlainTextAdapterExtension,
|
||||||
|
} from '@blocksuite/affine-block-embed';
|
||||||
|
import { LatexBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-latex';
|
||||||
|
import { ListBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-list';
|
||||||
|
import { ParagraphBlockPlainTextAdapterExtension } from '@blocksuite/affine-block-paragraph';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
export const defaultBlockPlainTextAdapterMatchers: ExtensionType[] = [
|
||||||
|
ParagraphBlockPlainTextAdapterExtension,
|
||||||
|
ListBlockPlainTextAdapterExtension,
|
||||||
|
DividerBlockPlainTextAdapterExtension,
|
||||||
|
CodeBlockPlainTextAdapterExtension,
|
||||||
|
BookmarkBlockPlainTextAdapterExtension,
|
||||||
|
EmbedFigmaBlockPlainTextAdapterExtension,
|
||||||
|
EmbedGithubBlockPlainTextAdapterExtension,
|
||||||
|
EmbedLoomBlockPlainTextAdapterExtension,
|
||||||
|
EmbedYoutubeBlockPlainTextAdapterExtension,
|
||||||
|
EmbedLinkedDocBlockPlainTextAdapterExtension,
|
||||||
|
EmbedSyncedDocBlockPlainTextAdapterExtension,
|
||||||
|
EmbedIframeBlockPlainTextAdapterExtension,
|
||||||
|
LatexBlockPlainTextAdapterExtension,
|
||||||
|
DatabaseBlockPlainTextAdapterExtension,
|
||||||
|
];
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-block-embed-doc';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-block-embed-doc/store';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-block-embed-doc/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-block-root/store';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-block-root/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-components/citation';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-components/resource';
|
|
||||||
@@ -1,24 +1,92 @@
|
|||||||
import { type effects as blockRootEffects } from '@blocksuite/affine-block-root/effects';
|
import { effects as blockAttachmentEffects } from '@blocksuite/affine-block-attachment/effects';
|
||||||
import { type effects as componentCaptionEffects } from '@blocksuite/affine-components/caption';
|
import { effects as blockBookmarkEffects } from '@blocksuite/affine-block-bookmark/effects';
|
||||||
import { type effects as componentColorPickerEffects } from '@blocksuite/affine-components/color-picker';
|
import { effects as blockCalloutEffects } from '@blocksuite/affine-block-callout/effects';
|
||||||
import { type effects as componentContextMenuEffects } from '@blocksuite/affine-components/context-menu';
|
import { effects as blockCodeEffects } from '@blocksuite/affine-block-code/effects';
|
||||||
import { type effects as componentDatePickerEffects } from '@blocksuite/affine-components/date-picker';
|
import { effects as blockDataViewEffects } from '@blocksuite/affine-block-data-view/effects';
|
||||||
import { type effects as componentDropIndicatorEffects } from '@blocksuite/affine-components/drop-indicator';
|
import { effects as blockDatabaseEffects } from '@blocksuite/affine-block-database/effects';
|
||||||
import { type effects as componentEmbedCardModalEffects } from '@blocksuite/affine-components/embed-card-modal';
|
import { effects as blockDividerEffects } from '@blocksuite/affine-block-divider/effects';
|
||||||
import { type effects as componentHighlightDropdownMenuEffects } from '@blocksuite/affine-components/highlight-dropdown-menu';
|
import { effects as blockEdgelessTextEffects } from '@blocksuite/affine-block-edgeless-text/effects';
|
||||||
import { type effects as componentLinkPreviewEffects } from '@blocksuite/affine-components/link-preview';
|
import { effects as blockEmbedEffects } from '@blocksuite/affine-block-embed/effects';
|
||||||
import { type effects as componentLinkedDocTitleEffects } from '@blocksuite/affine-components/linked-doc-title';
|
import { effects as blockFrameEffects } from '@blocksuite/affine-block-frame/effects';
|
||||||
import { type effects as componentPortalEffects } from '@blocksuite/affine-components/portal';
|
import { effects as blockImageEffects } from '@blocksuite/affine-block-image/effects';
|
||||||
import { type effects as componentToggleButtonEffects } from '@blocksuite/affine-components/toggle-button';
|
import { effects as blockLatexEffects } from '@blocksuite/affine-block-latex/effects';
|
||||||
import { type effects as componentToolbarEffects } from '@blocksuite/affine-components/toolbar';
|
import { effects as blockListEffects } from '@blocksuite/affine-block-list/effects';
|
||||||
import { type effects as componentViewDropdownMenuEffects } from '@blocksuite/affine-components/view-dropdown-menu';
|
import { effects as blockNoteEffects } from '@blocksuite/affine-block-note/effects';
|
||||||
import { type effects as richTextEffects } from '@blocksuite/affine-rich-text/effects';
|
import { effects as blockParagraphEffects } from '@blocksuite/affine-block-paragraph/effects';
|
||||||
import { type effects as stdEffects } from '@blocksuite/std/effects';
|
import { effects as blockRootEffects } from '@blocksuite/affine-block-root/effects';
|
||||||
|
import { effects as blockSurfaceEffects } from '@blocksuite/affine-block-surface/effects';
|
||||||
|
import { effects as blockSurfaceRefEffects } from '@blocksuite/affine-block-surface-ref/effects';
|
||||||
|
import { effects as blockTableEffects } from '@blocksuite/affine-block-table/effects';
|
||||||
|
import { BlockSelection } from '@blocksuite/affine-components/block-selection';
|
||||||
|
import { BlockZeroWidth } from '@blocksuite/affine-components/block-zero-width';
|
||||||
|
import { effects as componentCaptionEffects } from '@blocksuite/affine-components/caption';
|
||||||
|
import { effects as componentCardStyleDropdownMenuEffects } from '@blocksuite/affine-components/card-style-dropdown-menu';
|
||||||
|
import { effects as componentCitationEffects } from '@blocksuite/affine-components/citation';
|
||||||
|
import { effects as componentColorPickerEffects } from '@blocksuite/affine-components/color-picker';
|
||||||
|
import { effects as componentContextMenuEffects } from '@blocksuite/affine-components/context-menu';
|
||||||
|
import { effects as componentDatePickerEffects } from '@blocksuite/affine-components/date-picker';
|
||||||
|
import { effects as componentDropIndicatorEffects } from '@blocksuite/affine-components/drop-indicator';
|
||||||
|
import { effects as componentEdgelessLineStylesEffects } from '@blocksuite/affine-components/edgeless-line-styles-panel';
|
||||||
|
import { effects as componentEdgelessLineWidthEffects } from '@blocksuite/affine-components/edgeless-line-width-panel';
|
||||||
|
import { effects as componentEdgelessShapeColorPickerEffects } from '@blocksuite/affine-components/edgeless-shape-color-picker';
|
||||||
|
import { effects as componentEmbedCardModalEffects } from '@blocksuite/affine-components/embed-card-modal';
|
||||||
|
import { FilterableListComponent } from '@blocksuite/affine-components/filterable-list';
|
||||||
|
import { effects as componentHighlightDropdownMenuEffects } from '@blocksuite/affine-components/highlight-dropdown-menu';
|
||||||
|
import { IconButton } from '@blocksuite/affine-components/icon-button';
|
||||||
|
import { effects as componentLinkPreviewEffects } from '@blocksuite/affine-components/link-preview';
|
||||||
|
import { effects as componentLinkedDocTitleEffects } from '@blocksuite/affine-components/linked-doc-title';
|
||||||
|
import { effects as componentOpenDocDropdownMenuEffects } from '@blocksuite/affine-components/open-doc-dropdown-menu';
|
||||||
|
import { effects as componentPortalEffects } from '@blocksuite/affine-components/portal';
|
||||||
|
import { effects as componentSizeDropdownMenuEffects } from '@blocksuite/affine-components/size-dropdown-menu';
|
||||||
|
import { SmoothCorner } from '@blocksuite/affine-components/smooth-corner';
|
||||||
|
import { effects as componentToggleButtonEffects } from '@blocksuite/affine-components/toggle-button';
|
||||||
|
import { ToggleSwitch } from '@blocksuite/affine-components/toggle-switch';
|
||||||
|
import { effects as componentToolbarEffects } from '@blocksuite/affine-components/toolbar';
|
||||||
|
import { effects as componentTooltipContentWithShortcutEffects } from '@blocksuite/affine-components/tooltip-content-with-shortcut';
|
||||||
|
import { effects as componentViewDropdownMenuEffects } from '@blocksuite/affine-components/view-dropdown-menu';
|
||||||
|
import { effects as fragmentDocTitleEffects } from '@blocksuite/affine-fragment-doc-title/effects';
|
||||||
|
import { effects as fragmentFramePanelEffects } from '@blocksuite/affine-fragment-frame-panel/effects';
|
||||||
|
import { effects as fragmentOutlineEffects } from '@blocksuite/affine-fragment-outline/effects';
|
||||||
|
import { effects as inlineFootnoteEffects } from '@blocksuite/affine-inline-footnote/effects';
|
||||||
|
import { effects as inlineLatexEffects } from '@blocksuite/affine-inline-latex/effects';
|
||||||
|
import { effects as inlineLinkEffects } from '@blocksuite/affine-inline-link/effects';
|
||||||
|
import { effects as inlineMentionEffects } from '@blocksuite/affine-inline-mention';
|
||||||
|
import { effects as inlinePresetEffects } from '@blocksuite/affine-inline-preset/effects';
|
||||||
|
import { effects as inlineReferenceEffects } from '@blocksuite/affine-inline-reference/effects';
|
||||||
|
import { effects as richTextEffects } from '@blocksuite/affine-rich-text/effects';
|
||||||
|
import { effects as widgetDragHandleEffects } from '@blocksuite/affine-widget-drag-handle/effects';
|
||||||
|
import { effects as widgetEdgelessAutoConnectEffects } from '@blocksuite/affine-widget-edgeless-auto-connect/effects';
|
||||||
|
import { effects as widgetFrameTitleEffects } from '@blocksuite/affine-widget-frame-title/effects';
|
||||||
|
import { effects as widgetRemoteSelectionEffects } from '@blocksuite/affine-widget-remote-selection/effects';
|
||||||
|
import { effects as widgetScrollAnchoringEffects } from '@blocksuite/affine-widget-scroll-anchoring/effects';
|
||||||
|
import { effects as widgetSlashMenuEffects } from '@blocksuite/affine-widget-slash-menu/effects';
|
||||||
|
import { effects as widgetToolbarEffects } from '@blocksuite/affine-widget-toolbar/effects';
|
||||||
|
import { effects as dataViewEffects } from '@blocksuite/data-view/effects';
|
||||||
|
import { effects as stdEffects } from '@blocksuite/std/effects';
|
||||||
|
|
||||||
export declare const _GLOBAL_:
|
export declare const _GLOBAL_:
|
||||||
| typeof stdEffects
|
| typeof stdEffects
|
||||||
|
| typeof dataViewEffects
|
||||||
| typeof richTextEffects
|
| typeof richTextEffects
|
||||||
|
| typeof blockNoteEffects
|
||||||
|
| typeof blockAttachmentEffects
|
||||||
|
| typeof blockBookmarkEffects
|
||||||
|
| typeof blockFrameEffects
|
||||||
|
| typeof blockListEffects
|
||||||
|
| typeof blockParagraphEffects
|
||||||
|
| typeof blockEmbedEffects
|
||||||
|
| typeof blockSurfaceEffects
|
||||||
|
| typeof blockImageEffects
|
||||||
|
| typeof blockDatabaseEffects
|
||||||
|
| typeof blockSurfaceRefEffects
|
||||||
|
| typeof blockLatexEffects
|
||||||
|
| typeof blockEdgelessTextEffects
|
||||||
|
| typeof blockDividerEffects
|
||||||
|
| typeof blockDataViewEffects
|
||||||
|
| typeof blockCodeEffects
|
||||||
|
| typeof blockTableEffects
|
||||||
| typeof blockRootEffects
|
| typeof blockRootEffects
|
||||||
|
| typeof blockCalloutEffects
|
||||||
| typeof componentCaptionEffects
|
| typeof componentCaptionEffects
|
||||||
| typeof componentContextMenuEffects
|
| typeof componentContextMenuEffects
|
||||||
| typeof componentDatePickerEffects
|
| typeof componentDatePickerEffects
|
||||||
@@ -31,4 +99,89 @@ export declare const _GLOBAL_:
|
|||||||
| typeof componentToolbarEffects
|
| typeof componentToolbarEffects
|
||||||
| typeof componentToggleButtonEffects
|
| typeof componentToggleButtonEffects
|
||||||
| typeof componentColorPickerEffects
|
| typeof componentColorPickerEffects
|
||||||
| typeof componentViewDropdownMenuEffects;
|
| typeof componentViewDropdownMenuEffects
|
||||||
|
| typeof widgetScrollAnchoringEffects
|
||||||
|
| typeof widgetFrameTitleEffects
|
||||||
|
| typeof widgetRemoteSelectionEffects
|
||||||
|
| typeof widgetDragHandleEffects
|
||||||
|
| typeof widgetEdgelessAutoConnectEffects
|
||||||
|
| typeof widgetToolbarEffects
|
||||||
|
| typeof widgetSlashMenuEffects
|
||||||
|
| typeof fragmentDocTitleEffects
|
||||||
|
| typeof fragmentFramePanelEffects
|
||||||
|
| typeof fragmentOutlineEffects;
|
||||||
|
|
||||||
|
export function effects() {
|
||||||
|
stdEffects();
|
||||||
|
|
||||||
|
dataViewEffects();
|
||||||
|
richTextEffects();
|
||||||
|
|
||||||
|
inlineReferenceEffects();
|
||||||
|
inlinePresetEffects();
|
||||||
|
inlineLinkEffects();
|
||||||
|
inlineFootnoteEffects();
|
||||||
|
inlineLatexEffects();
|
||||||
|
inlineMentionEffects();
|
||||||
|
|
||||||
|
blockNoteEffects();
|
||||||
|
blockAttachmentEffects();
|
||||||
|
blockBookmarkEffects();
|
||||||
|
blockFrameEffects();
|
||||||
|
blockListEffects();
|
||||||
|
blockParagraphEffects();
|
||||||
|
blockEmbedEffects();
|
||||||
|
blockSurfaceEffects();
|
||||||
|
blockImageEffects();
|
||||||
|
blockDatabaseEffects();
|
||||||
|
blockSurfaceRefEffects();
|
||||||
|
blockLatexEffects();
|
||||||
|
blockEdgelessTextEffects();
|
||||||
|
blockDividerEffects();
|
||||||
|
blockDataViewEffects();
|
||||||
|
blockCodeEffects();
|
||||||
|
blockTableEffects();
|
||||||
|
blockRootEffects();
|
||||||
|
blockCalloutEffects();
|
||||||
|
|
||||||
|
componentCaptionEffects();
|
||||||
|
componentContextMenuEffects();
|
||||||
|
componentDatePickerEffects();
|
||||||
|
componentPortalEffects();
|
||||||
|
componentToolbarEffects();
|
||||||
|
componentDropIndicatorEffects();
|
||||||
|
componentToggleButtonEffects();
|
||||||
|
componentColorPickerEffects();
|
||||||
|
componentEmbedCardModalEffects();
|
||||||
|
componentLinkPreviewEffects();
|
||||||
|
componentLinkedDocTitleEffects();
|
||||||
|
componentCitationEffects();
|
||||||
|
componentCardStyleDropdownMenuEffects();
|
||||||
|
componentHighlightDropdownMenuEffects();
|
||||||
|
componentViewDropdownMenuEffects();
|
||||||
|
componentTooltipContentWithShortcutEffects();
|
||||||
|
componentSizeDropdownMenuEffects();
|
||||||
|
componentEdgelessLineWidthEffects();
|
||||||
|
componentEdgelessLineStylesEffects();
|
||||||
|
componentEdgelessShapeColorPickerEffects();
|
||||||
|
componentOpenDocDropdownMenuEffects();
|
||||||
|
|
||||||
|
widgetScrollAnchoringEffects();
|
||||||
|
widgetFrameTitleEffects();
|
||||||
|
widgetRemoteSelectionEffects();
|
||||||
|
widgetDragHandleEffects();
|
||||||
|
widgetEdgelessAutoConnectEffects();
|
||||||
|
widgetSlashMenuEffects();
|
||||||
|
widgetToolbarEffects();
|
||||||
|
|
||||||
|
fragmentDocTitleEffects();
|
||||||
|
fragmentFramePanelEffects();
|
||||||
|
fragmentOutlineEffects();
|
||||||
|
|
||||||
|
customElements.define('icon-button', IconButton);
|
||||||
|
customElements.define('smooth-corner', SmoothCorner);
|
||||||
|
customElements.define('toggle-switch', ToggleSwitch);
|
||||||
|
customElements.define('affine-filterable-list', FilterableListComponent);
|
||||||
|
customElements.define('block-zero-width', BlockZeroWidth);
|
||||||
|
customElements.define('affine-block-selection', BlockSelection);
|
||||||
|
}
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
import { effects as blockRootEffects } from '@blocksuite/affine-block-root/effects';
|
||||||
|
import { effects as fragmentDocTitleEffects } from '@blocksuite/affine-fragment-doc-title/effects';
|
||||||
|
import { effects as fragmentFramePanelEffects } from '@blocksuite/affine-fragment-frame-panel/effects';
|
||||||
|
import { effects as fragmentOutlineEffects } from '@blocksuite/affine-fragment-outline/effects';
|
||||||
|
|
||||||
|
export function effects() {
|
||||||
|
blockRootEffects();
|
||||||
|
|
||||||
|
fragmentDocTitleEffects();
|
||||||
|
fragmentFramePanelEffects();
|
||||||
|
fragmentOutlineEffects();
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
import {
|
||||||
|
RootBlockHtmlAdapterExtension,
|
||||||
|
RootBlockMarkdownAdapterExtension,
|
||||||
|
RootBlockNotionHtmlAdapterExtension,
|
||||||
|
} from '@blocksuite/affine-block-root';
|
||||||
|
import {
|
||||||
|
type StoreExtensionContext,
|
||||||
|
StoreExtensionProvider,
|
||||||
|
} from '@blocksuite/affine-ext-loader';
|
||||||
|
import { RootBlockSchemaExtension } from '@blocksuite/affine-model';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
const defaultBlockHtmlAdapterMatchers = [RootBlockHtmlAdapterExtension];
|
||||||
|
|
||||||
|
const defaultBlockMarkdownAdapterMatchers = [RootBlockMarkdownAdapterExtension];
|
||||||
|
|
||||||
|
const defaultBlockNotionHtmlAdapterMatchers: ExtensionType[] = [
|
||||||
|
RootBlockNotionHtmlAdapterExtension,
|
||||||
|
];
|
||||||
|
|
||||||
|
function getHtmlAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [...defaultBlockHtmlAdapterMatchers];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getMarkdownAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [...defaultBlockMarkdownAdapterMatchers];
|
||||||
|
}
|
||||||
|
|
||||||
|
function getNotionHtmlAdapterExtensions(): ExtensionType[] {
|
||||||
|
return [...defaultBlockNotionHtmlAdapterMatchers];
|
||||||
|
}
|
||||||
|
|
||||||
|
const MigratingStoreExtensions: ExtensionType[] = [
|
||||||
|
RootBlockSchemaExtension,
|
||||||
|
|
||||||
|
getHtmlAdapterExtensions(),
|
||||||
|
getMarkdownAdapterExtensions(),
|
||||||
|
getNotionHtmlAdapterExtensions(),
|
||||||
|
].flat();
|
||||||
|
|
||||||
|
export class MigratingStoreExtension extends StoreExtensionProvider {
|
||||||
|
override name = 'migrating';
|
||||||
|
|
||||||
|
override setup(context: StoreExtensionContext) {
|
||||||
|
super.setup(context);
|
||||||
|
context.register(MigratingStoreExtensions);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
import {
|
||||||
|
type ViewExtensionContext,
|
||||||
|
ViewExtensionProvider,
|
||||||
|
} from '@blocksuite/affine-ext-loader';
|
||||||
|
|
||||||
|
import { effects } from './effects';
|
||||||
|
import {
|
||||||
|
MigratingEdgelessEditorBlockSpecs,
|
||||||
|
MigratingPageEditorBlockSpecs,
|
||||||
|
MigratingPreviewEdgelessEditorBlockSpecs,
|
||||||
|
MigratingPreviewPageEditorBlockSpecs,
|
||||||
|
} from './migrating';
|
||||||
|
|
||||||
|
export class MigratingViewExtension extends ViewExtensionProvider {
|
||||||
|
override name = 'migrating';
|
||||||
|
|
||||||
|
override effect() {
|
||||||
|
super.effect();
|
||||||
|
effects();
|
||||||
|
}
|
||||||
|
|
||||||
|
override setup(context: ViewExtensionContext) {
|
||||||
|
super.setup(context);
|
||||||
|
const scope = context.scope;
|
||||||
|
if (scope === 'preview-page') {
|
||||||
|
context.register(MigratingPreviewPageEditorBlockSpecs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (scope === 'preview-edgeless') {
|
||||||
|
context.register(MigratingPreviewEdgelessEditorBlockSpecs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (scope === 'page' || scope === 'mobile-page') {
|
||||||
|
context.register(MigratingPageEditorBlockSpecs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (scope === 'edgeless' || scope === 'mobile-edgeless') {
|
||||||
|
context.register(MigratingEdgelessEditorBlockSpecs);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
import {
|
||||||
|
EdgelessBuiltInSpecs,
|
||||||
|
PageRootBlockSpec,
|
||||||
|
PreviewEdgelessRootBlockSpec,
|
||||||
|
PreviewPageRootBlockSpec,
|
||||||
|
ReadOnlyClipboard,
|
||||||
|
} from '@blocksuite/affine-block-root';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
|
||||||
|
export const MigratingEdgelessEditorBlockSpecs: ExtensionType[] = [
|
||||||
|
EdgelessBuiltInSpecs,
|
||||||
|
].flat();
|
||||||
|
|
||||||
|
export const MigratingPageEditorBlockSpecs: ExtensionType[] = [
|
||||||
|
PageRootBlockSpec,
|
||||||
|
].flat();
|
||||||
|
|
||||||
|
export const MigratingPreviewEdgelessEditorBlockSpecs: ExtensionType[] = [
|
||||||
|
PreviewEdgelessRootBlockSpec,
|
||||||
|
ReadOnlyClipboard,
|
||||||
|
].flat();
|
||||||
|
|
||||||
|
export const MigratingPreviewPageEditorBlockSpecs: ExtensionType[] = [
|
||||||
|
PreviewPageRootBlockSpec,
|
||||||
|
ReadOnlyClipboard,
|
||||||
|
].flat();
|
||||||
@@ -7,14 +7,12 @@ import { DatabaseStoreExtension } from '@blocksuite/affine-block-database/store'
|
|||||||
import { DividerStoreExtension } from '@blocksuite/affine-block-divider/store';
|
import { DividerStoreExtension } from '@blocksuite/affine-block-divider/store';
|
||||||
import { EdgelessTextStoreExtension } from '@blocksuite/affine-block-edgeless-text/store';
|
import { EdgelessTextStoreExtension } from '@blocksuite/affine-block-edgeless-text/store';
|
||||||
import { EmbedStoreExtension } from '@blocksuite/affine-block-embed/store';
|
import { EmbedStoreExtension } from '@blocksuite/affine-block-embed/store';
|
||||||
import { EmbedDocStoreExtension } from '@blocksuite/affine-block-embed-doc/store';
|
|
||||||
import { FrameStoreExtension } from '@blocksuite/affine-block-frame/store';
|
import { FrameStoreExtension } from '@blocksuite/affine-block-frame/store';
|
||||||
import { ImageStoreExtension } from '@blocksuite/affine-block-image/store';
|
import { ImageStoreExtension } from '@blocksuite/affine-block-image/store';
|
||||||
import { LatexStoreExtension } from '@blocksuite/affine-block-latex/store';
|
import { LatexStoreExtension } from '@blocksuite/affine-block-latex/store';
|
||||||
import { ListStoreExtension } from '@blocksuite/affine-block-list/store';
|
import { ListStoreExtension } from '@blocksuite/affine-block-list/store';
|
||||||
import { NoteStoreExtension } from '@blocksuite/affine-block-note/store';
|
import { NoteStoreExtension } from '@blocksuite/affine-block-note/store';
|
||||||
import { ParagraphStoreExtension } from '@blocksuite/affine-block-paragraph/store';
|
import { ParagraphStoreExtension } from '@blocksuite/affine-block-paragraph/store';
|
||||||
import { RootStoreExtension } from '@blocksuite/affine-block-root/store';
|
|
||||||
import { SurfaceStoreExtension } from '@blocksuite/affine-block-surface/store';
|
import { SurfaceStoreExtension } from '@blocksuite/affine-block-surface/store';
|
||||||
import { SurfaceRefStoreExtension } from '@blocksuite/affine-block-surface-ref/store';
|
import { SurfaceRefStoreExtension } from '@blocksuite/affine-block-surface-ref/store';
|
||||||
import { TableStoreExtension } from '@blocksuite/affine-block-table/store';
|
import { TableStoreExtension } from '@blocksuite/affine-block-table/store';
|
||||||
@@ -31,6 +29,8 @@ import { LinkStoreExtension } from '@blocksuite/affine-inline-link/store';
|
|||||||
import { InlinePresetStoreExtension } from '@blocksuite/affine-inline-preset/store';
|
import { InlinePresetStoreExtension } from '@blocksuite/affine-inline-preset/store';
|
||||||
import { ReferenceStoreExtension } from '@blocksuite/affine-inline-reference/store';
|
import { ReferenceStoreExtension } from '@blocksuite/affine-inline-reference/store';
|
||||||
|
|
||||||
|
import { MigratingStoreExtension } from './migrating-store';
|
||||||
|
|
||||||
export function getInternalStoreExtensions() {
|
export function getInternalStoreExtensions() {
|
||||||
return [
|
return [
|
||||||
FoundationStoreExtension,
|
FoundationStoreExtension,
|
||||||
@@ -44,7 +44,6 @@ export function getInternalStoreExtensions() {
|
|||||||
DividerStoreExtension,
|
DividerStoreExtension,
|
||||||
EdgelessTextStoreExtension,
|
EdgelessTextStoreExtension,
|
||||||
EmbedStoreExtension,
|
EmbedStoreExtension,
|
||||||
EmbedDocStoreExtension,
|
|
||||||
FrameStoreExtension,
|
FrameStoreExtension,
|
||||||
ImageStoreExtension,
|
ImageStoreExtension,
|
||||||
LatexStoreExtension,
|
LatexStoreExtension,
|
||||||
@@ -54,7 +53,6 @@ export function getInternalStoreExtensions() {
|
|||||||
SurfaceRefStoreExtension,
|
SurfaceRefStoreExtension,
|
||||||
TableStoreExtension,
|
TableStoreExtension,
|
||||||
SurfaceStoreExtension,
|
SurfaceStoreExtension,
|
||||||
RootStoreExtension,
|
|
||||||
|
|
||||||
FootnoteStoreExtension,
|
FootnoteStoreExtension,
|
||||||
LinkStoreExtension,
|
LinkStoreExtension,
|
||||||
@@ -68,5 +66,7 @@ export function getInternalStoreExtensions() {
|
|||||||
ConnectorStoreExtension,
|
ConnectorStoreExtension,
|
||||||
GroupStoreExtension,
|
GroupStoreExtension,
|
||||||
TextStoreExtension,
|
TextStoreExtension,
|
||||||
|
|
||||||
|
MigratingStoreExtension,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,22 +7,16 @@ import { DatabaseViewExtension } from '@blocksuite/affine-block-database/view';
|
|||||||
import { DividerViewExtension } from '@blocksuite/affine-block-divider/view';
|
import { DividerViewExtension } from '@blocksuite/affine-block-divider/view';
|
||||||
import { EdgelessTextViewExtension } from '@blocksuite/affine-block-edgeless-text/view';
|
import { EdgelessTextViewExtension } from '@blocksuite/affine-block-edgeless-text/view';
|
||||||
import { EmbedViewExtension } from '@blocksuite/affine-block-embed/view';
|
import { EmbedViewExtension } from '@blocksuite/affine-block-embed/view';
|
||||||
import { EmbedDocViewExtension } from '@blocksuite/affine-block-embed-doc/view';
|
|
||||||
import { FrameViewExtension } from '@blocksuite/affine-block-frame/view';
|
import { FrameViewExtension } from '@blocksuite/affine-block-frame/view';
|
||||||
import { ImageViewExtension } from '@blocksuite/affine-block-image/view';
|
import { ImageViewExtension } from '@blocksuite/affine-block-image/view';
|
||||||
import { LatexViewExtension } from '@blocksuite/affine-block-latex/view';
|
import { LatexViewExtension } from '@blocksuite/affine-block-latex/view';
|
||||||
import { ListViewExtension } from '@blocksuite/affine-block-list/view';
|
import { ListViewExtension } from '@blocksuite/affine-block-list/view';
|
||||||
import { NoteViewExtension } from '@blocksuite/affine-block-note/view';
|
import { NoteViewExtension } from '@blocksuite/affine-block-note/view';
|
||||||
import { ParagraphViewExtension } from '@blocksuite/affine-block-paragraph/view';
|
import { ParagraphViewExtension } from '@blocksuite/affine-block-paragraph/view';
|
||||||
import { RootViewExtension } from '@blocksuite/affine-block-root/view';
|
|
||||||
import { SurfaceViewExtension } from '@blocksuite/affine-block-surface/view';
|
import { SurfaceViewExtension } from '@blocksuite/affine-block-surface/view';
|
||||||
import { SurfaceRefViewExtension } from '@blocksuite/affine-block-surface-ref/view';
|
import { SurfaceRefViewExtension } from '@blocksuite/affine-block-surface-ref/view';
|
||||||
import { TableViewExtension } from '@blocksuite/affine-block-table/view';
|
import { TableViewExtension } from '@blocksuite/affine-block-table/view';
|
||||||
import { FoundationViewExtension } from '@blocksuite/affine-foundation/view';
|
import { FoundationViewExtension } from '@blocksuite/affine-foundation/view';
|
||||||
import { AdapterPanelViewExtension } from '@blocksuite/affine-fragment-adapter-panel/view';
|
|
||||||
import { DocTitleViewExtension } from '@blocksuite/affine-fragment-doc-title/view';
|
|
||||||
import { FramePanelViewExtension } from '@blocksuite/affine-fragment-frame-panel/view';
|
|
||||||
import { OutlineViewExtension } from '@blocksuite/affine-fragment-outline/view';
|
|
||||||
import { BrushViewExtension } from '@blocksuite/affine-gfx-brush/view';
|
import { BrushViewExtension } from '@blocksuite/affine-gfx-brush/view';
|
||||||
import { ConnectorViewExtension } from '@blocksuite/affine-gfx-connector/view';
|
import { ConnectorViewExtension } from '@blocksuite/affine-gfx-connector/view';
|
||||||
import { GroupViewExtension } from '@blocksuite/affine-gfx-group/view';
|
import { GroupViewExtension } from '@blocksuite/affine-gfx-group/view';
|
||||||
@@ -41,14 +35,11 @@ import { InlinePresetViewExtension } from '@blocksuite/affine-inline-preset/view
|
|||||||
import { ReferenceViewExtension } from '@blocksuite/affine-inline-reference/view';
|
import { ReferenceViewExtension } from '@blocksuite/affine-inline-reference/view';
|
||||||
import { DragHandleViewExtension } from '@blocksuite/affine-widget-drag-handle/view';
|
import { DragHandleViewExtension } from '@blocksuite/affine-widget-drag-handle/view';
|
||||||
import { EdgelessAutoConnectViewExtension } from '@blocksuite/affine-widget-edgeless-auto-connect/view';
|
import { EdgelessAutoConnectViewExtension } from '@blocksuite/affine-widget-edgeless-auto-connect/view';
|
||||||
import { EdgelessDraggingAreaViewExtension } from '@blocksuite/affine-widget-edgeless-dragging-area/view';
|
|
||||||
import { EdgelessSelectedRectViewExtension } from '@blocksuite/affine-widget-edgeless-selected-rect/view';
|
|
||||||
import { EdgelessToolbarViewExtension } from '@blocksuite/affine-widget-edgeless-toolbar/view';
|
import { EdgelessToolbarViewExtension } from '@blocksuite/affine-widget-edgeless-toolbar/view';
|
||||||
import { EdgelessZoomToolbarViewExtension } from '@blocksuite/affine-widget-edgeless-zoom-toolbar/view';
|
import { EdgelessZoomToolbarViewExtension } from '@blocksuite/affine-widget-edgeless-zoom-toolbar/view';
|
||||||
import { FrameTitleViewExtension } from '@blocksuite/affine-widget-frame-title/view';
|
import { FrameTitleViewExtension } from '@blocksuite/affine-widget-frame-title/view';
|
||||||
import { KeyboardToolbarViewExtension } from '@blocksuite/affine-widget-keyboard-toolbar/view';
|
import { KeyboardToolbarViewExtension } from '@blocksuite/affine-widget-keyboard-toolbar/view';
|
||||||
import { LinkedDocViewExtension } from '@blocksuite/affine-widget-linked-doc/view';
|
import { LinkedDocViewExtension } from '@blocksuite/affine-widget-linked-doc/view';
|
||||||
import { NoteSlicerViewExtension } from '@blocksuite/affine-widget-note-slicer/view';
|
|
||||||
import { PageDraggingAreaViewExtension } from '@blocksuite/affine-widget-page-dragging-area/view';
|
import { PageDraggingAreaViewExtension } from '@blocksuite/affine-widget-page-dragging-area/view';
|
||||||
import { RemoteSelectionViewExtension } from '@blocksuite/affine-widget-remote-selection/view';
|
import { RemoteSelectionViewExtension } from '@blocksuite/affine-widget-remote-selection/view';
|
||||||
import { ScrollAnchoringViewExtension } from '@blocksuite/affine-widget-scroll-anchoring/view';
|
import { ScrollAnchoringViewExtension } from '@blocksuite/affine-widget-scroll-anchoring/view';
|
||||||
@@ -56,6 +47,8 @@ import { SlashMenuViewExtension } from '@blocksuite/affine-widget-slash-menu/vie
|
|||||||
import { ToolbarViewExtension } from '@blocksuite/affine-widget-toolbar/view';
|
import { ToolbarViewExtension } from '@blocksuite/affine-widget-toolbar/view';
|
||||||
import { ViewportOverlayViewExtension } from '@blocksuite/affine-widget-viewport-overlay/view';
|
import { ViewportOverlayViewExtension } from '@blocksuite/affine-widget-viewport-overlay/view';
|
||||||
|
|
||||||
|
import { MigratingViewExtension } from './migrating-view';
|
||||||
|
|
||||||
export function getInternalViewExtensions() {
|
export function getInternalViewExtensions() {
|
||||||
return [
|
return [
|
||||||
FoundationViewExtension,
|
FoundationViewExtension,
|
||||||
@@ -82,7 +75,6 @@ export function getInternalViewExtensions() {
|
|||||||
DividerViewExtension,
|
DividerViewExtension,
|
||||||
EdgelessTextViewExtension,
|
EdgelessTextViewExtension,
|
||||||
EmbedViewExtension,
|
EmbedViewExtension,
|
||||||
EmbedDocViewExtension,
|
|
||||||
FrameViewExtension,
|
FrameViewExtension,
|
||||||
ImageViewExtension,
|
ImageViewExtension,
|
||||||
LatexViewExtension,
|
LatexViewExtension,
|
||||||
@@ -92,7 +84,6 @@ export function getInternalViewExtensions() {
|
|||||||
SurfaceRefViewExtension,
|
SurfaceRefViewExtension,
|
||||||
TableViewExtension,
|
TableViewExtension,
|
||||||
SurfaceViewExtension,
|
SurfaceViewExtension,
|
||||||
RootViewExtension,
|
|
||||||
|
|
||||||
// Inline
|
// Inline
|
||||||
FootnoteViewExtension,
|
FootnoteViewExtension,
|
||||||
@@ -103,9 +94,10 @@ export function getInternalViewExtensions() {
|
|||||||
InlinePresetViewExtension,
|
InlinePresetViewExtension,
|
||||||
|
|
||||||
// Widget
|
// Widget
|
||||||
// order will affect the z-index of the widget
|
|
||||||
DragHandleViewExtension,
|
DragHandleViewExtension,
|
||||||
EdgelessAutoConnectViewExtension,
|
EdgelessAutoConnectViewExtension,
|
||||||
|
EdgelessToolbarViewExtension,
|
||||||
|
MigratingViewExtension,
|
||||||
FrameTitleViewExtension,
|
FrameTitleViewExtension,
|
||||||
KeyboardToolbarViewExtension,
|
KeyboardToolbarViewExtension,
|
||||||
LinkedDocViewExtension,
|
LinkedDocViewExtension,
|
||||||
@@ -116,15 +108,5 @@ export function getInternalViewExtensions() {
|
|||||||
ViewportOverlayViewExtension,
|
ViewportOverlayViewExtension,
|
||||||
EdgelessZoomToolbarViewExtension,
|
EdgelessZoomToolbarViewExtension,
|
||||||
PageDraggingAreaViewExtension,
|
PageDraggingAreaViewExtension,
|
||||||
EdgelessSelectedRectViewExtension,
|
|
||||||
EdgelessDraggingAreaViewExtension,
|
|
||||||
NoteSlicerViewExtension,
|
|
||||||
EdgelessToolbarViewExtension,
|
|
||||||
|
|
||||||
// Fragment
|
|
||||||
DocTitleViewExtension,
|
|
||||||
FramePanelViewExtension,
|
|
||||||
OutlineViewExtension,
|
|
||||||
AdapterPanelViewExtension,
|
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-foundation/store';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-foundation/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-fragment-adapter-panel';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-fragment-adapter-panel/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-fragment-doc-title/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-fragment-frame-panel/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-fragment-outline/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-edgeless-dragging-area';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-edgeless-dragging-area/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-edgeless-selected-rect';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-edgeless-selected-rect/view';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-note-slicer';
|
|
||||||
@@ -1 +0,0 @@
|
|||||||
export * from '@blocksuite/affine-widget-note-slicer/view';
|
|
||||||
@@ -16,7 +16,6 @@
|
|||||||
{ "path": "../blocks/divider" },
|
{ "path": "../blocks/divider" },
|
||||||
{ "path": "../blocks/edgeless-text" },
|
{ "path": "../blocks/edgeless-text" },
|
||||||
{ "path": "../blocks/embed" },
|
{ "path": "../blocks/embed" },
|
||||||
{ "path": "../blocks/embed-doc" },
|
|
||||||
{ "path": "../blocks/frame" },
|
{ "path": "../blocks/frame" },
|
||||||
{ "path": "../blocks/image" },
|
{ "path": "../blocks/image" },
|
||||||
{ "path": "../blocks/latex" },
|
{ "path": "../blocks/latex" },
|
||||||
@@ -30,7 +29,6 @@
|
|||||||
{ "path": "../components" },
|
{ "path": "../components" },
|
||||||
{ "path": "../ext-loader" },
|
{ "path": "../ext-loader" },
|
||||||
{ "path": "../foundation" },
|
{ "path": "../foundation" },
|
||||||
{ "path": "../fragments/adapter-panel" },
|
|
||||||
{ "path": "../fragments/doc-title" },
|
{ "path": "../fragments/doc-title" },
|
||||||
{ "path": "../fragments/frame-panel" },
|
{ "path": "../fragments/frame-panel" },
|
||||||
{ "path": "../fragments/outline" },
|
{ "path": "../fragments/outline" },
|
||||||
@@ -56,14 +54,11 @@
|
|||||||
{ "path": "../shared" },
|
{ "path": "../shared" },
|
||||||
{ "path": "../widgets/drag-handle" },
|
{ "path": "../widgets/drag-handle" },
|
||||||
{ "path": "../widgets/edgeless-auto-connect" },
|
{ "path": "../widgets/edgeless-auto-connect" },
|
||||||
{ "path": "../widgets/edgeless-dragging-area" },
|
|
||||||
{ "path": "../widgets/edgeless-selected-rect" },
|
|
||||||
{ "path": "../widgets/edgeless-toolbar" },
|
{ "path": "../widgets/edgeless-toolbar" },
|
||||||
{ "path": "../widgets/edgeless-zoom-toolbar" },
|
{ "path": "../widgets/edgeless-zoom-toolbar" },
|
||||||
{ "path": "../widgets/frame-title" },
|
{ "path": "../widgets/frame-title" },
|
||||||
{ "path": "../widgets/keyboard-toolbar" },
|
{ "path": "../widgets/keyboard-toolbar" },
|
||||||
{ "path": "../widgets/linked-doc" },
|
{ "path": "../widgets/linked-doc" },
|
||||||
{ "path": "../widgets/note-slicer" },
|
|
||||||
{ "path": "../widgets/page-dragging-area" },
|
{ "path": "../widgets/page-dragging-area" },
|
||||||
{ "path": "../widgets/remote-selection" },
|
{ "path": "../widgets/remote-selection" },
|
||||||
{ "path": "../widgets/scroll-anchoring" },
|
{ "path": "../widgets/scroll-anchoring" },
|
||||||
|
|||||||
@@ -10,6 +10,7 @@
|
|||||||
"author": "toeverything",
|
"author": "toeverything",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@blocksuite/affine-block-embed": "workspace:*",
|
||||||
"@blocksuite/affine-block-surface": "workspace:*",
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-ext-loader": "workspace:*",
|
"@blocksuite/affine-ext-loader": "workspace:*",
|
||||||
@@ -23,8 +24,8 @@
|
|||||||
"@floating-ui/dom": "^1.6.13",
|
"@floating-ui/dom": "^1.6.13",
|
||||||
"@lit/context": "^1.1.2",
|
"@lit/context": "^1.1.2",
|
||||||
"@preact/signals-core": "^1.8.0",
|
"@preact/signals-core": "^1.8.0",
|
||||||
"@toeverything/theme": "^1.1.15",
|
"@toeverything/theme": "^1.1.12",
|
||||||
"file-type": "^21.0.0",
|
"file-type": "^20.0.0",
|
||||||
"lit": "^3.2.0",
|
"lit": "^3.2.0",
|
||||||
"minimatch": "^10.0.1",
|
"minimatch": "^10.0.1",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
@@ -32,6 +33,7 @@
|
|||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts",
|
".": "./src/index.ts",
|
||||||
|
"./effects": "./src/effects.ts",
|
||||||
"./store": "./src/store.ts",
|
"./store": "./src/store.ts",
|
||||||
"./view": "./src/view.ts"
|
"./view": "./src/view.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
isFootnoteDefinitionNode,
|
isFootnoteDefinitionNode,
|
||||||
type MarkdownAST,
|
type MarkdownAST,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
|
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||||
import { nanoid } from '@blocksuite/store';
|
import { nanoid } from '@blocksuite/store';
|
||||||
|
|
||||||
const isAttachmentFootnoteDefinitionNode = (node: MarkdownAST) => {
|
const isAttachmentFootnoteDefinitionNode = (node: MarkdownAST) => {
|
||||||
@@ -35,7 +36,15 @@ export const attachmentBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher
|
|||||||
fromMatch: o => o.node.flavour === AttachmentBlockSchema.model.flavour,
|
fromMatch: o => o.node.flavour === AttachmentBlockSchema.model.flavour,
|
||||||
toBlockSnapshot: {
|
toBlockSnapshot: {
|
||||||
enter: (o, context) => {
|
enter: (o, context) => {
|
||||||
if (!isFootnoteDefinitionNode(o.node)) {
|
const { provider } = context;
|
||||||
|
let enableCitation = false;
|
||||||
|
try {
|
||||||
|
const featureFlagService = provider?.get(FeatureFlagService);
|
||||||
|
enableCitation = !!featureFlagService?.getFlag('enable_citation');
|
||||||
|
} catch {
|
||||||
|
enableCitation = false;
|
||||||
|
}
|
||||||
|
if (!isFootnoteDefinitionNode(o.node) || !enableCitation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +73,6 @@ export const attachmentBlockMarkdownAdapterMatcher: BlockMarkdownAdapterMatcher
|
|||||||
name: fileName,
|
name: fileName,
|
||||||
sourceId: blobId,
|
sourceId: blobId,
|
||||||
footnoteIdentifier,
|
footnoteIdentifier,
|
||||||
style: 'citation',
|
|
||||||
},
|
},
|
||||||
children: [],
|
children: [],
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,31 +1,20 @@
|
|||||||
|
import { getEmbedCardIcons } from '@blocksuite/affine-block-embed';
|
||||||
import {
|
import {
|
||||||
CaptionedBlockComponent,
|
CaptionedBlockComponent,
|
||||||
SelectedStyle,
|
SelectedStyle,
|
||||||
} from '@blocksuite/affine-components/caption';
|
} from '@blocksuite/affine-components/caption';
|
||||||
import {
|
import { getAttachmentFileIcon } from '@blocksuite/affine-components/icons';
|
||||||
getAttachmentFileIcon,
|
|
||||||
LoadingIcon,
|
|
||||||
} from '@blocksuite/affine-components/icons';
|
|
||||||
import { Peekable } from '@blocksuite/affine-components/peek';
|
import { Peekable } from '@blocksuite/affine-components/peek';
|
||||||
import {
|
|
||||||
type ResolvedStateInfo,
|
|
||||||
ResourceController,
|
|
||||||
} from '@blocksuite/affine-components/resource';
|
|
||||||
import { toast } from '@blocksuite/affine-components/toast';
|
import { toast } from '@blocksuite/affine-components/toast';
|
||||||
import {
|
import {
|
||||||
type AttachmentBlockModel,
|
type AttachmentBlockModel,
|
||||||
AttachmentBlockStyles,
|
AttachmentBlockStyles,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import {
|
import {
|
||||||
CitationProvider,
|
|
||||||
DocModeProvider,
|
|
||||||
FileSizeLimitProvider,
|
FileSizeLimitProvider,
|
||||||
TelemetryProvider,
|
ThemeProvider,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import { humanFileSize } from '@blocksuite/affine-shared/utils';
|
||||||
formatSize,
|
|
||||||
openSingleFileWith,
|
|
||||||
} from '@blocksuite/affine-shared/utils';
|
|
||||||
import {
|
import {
|
||||||
AttachmentIcon,
|
AttachmentIcon,
|
||||||
ResetIcon,
|
ResetIcon,
|
||||||
@@ -33,27 +22,23 @@ import {
|
|||||||
WarningIcon,
|
WarningIcon,
|
||||||
} from '@blocksuite/icons/lit';
|
} from '@blocksuite/icons/lit';
|
||||||
import { BlockSelection } from '@blocksuite/std';
|
import { BlockSelection } from '@blocksuite/std';
|
||||||
import { nanoid, Slice } from '@blocksuite/store';
|
import { Slice } from '@blocksuite/store';
|
||||||
import { batch, computed, signal } from '@preact/signals-core';
|
import { type BlobState } from '@blocksuite/sync';
|
||||||
|
import { effect, signal } from '@preact/signals-core';
|
||||||
import { html, type TemplateResult } from 'lit';
|
import { html, type TemplateResult } from 'lit';
|
||||||
|
import { property } from 'lit/decorators.js';
|
||||||
import { choose } from 'lit/directives/choose.js';
|
import { choose } from 'lit/directives/choose.js';
|
||||||
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||||
import { guard } from 'lit/directives/guard.js';
|
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
import { when } from 'lit/directives/when.js';
|
import { when } from 'lit/directives/when.js';
|
||||||
import { filter } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import { AttachmentEmbedProvider } from './embed';
|
import { AttachmentEmbedProvider } from './embed';
|
||||||
import { styles } from './styles';
|
import { styles } from './styles';
|
||||||
import { downloadAttachmentBlob, getFileType, refreshData } from './utils';
|
import { downloadAttachmentBlob, refreshData } from './utils';
|
||||||
|
type State = 'loading' | 'uploading' | 'warning' | 'oversize' | 'none';
|
||||||
type AttachmentResolvedStateInfo = ResolvedStateInfo & {
|
|
||||||
kind?: TemplateResult;
|
|
||||||
};
|
|
||||||
|
|
||||||
@Peekable({
|
@Peekable({
|
||||||
enableOn: ({ model }: AttachmentBlockComponent) => {
|
enableOn: ({ model }: AttachmentBlockComponent) => {
|
||||||
return !model.store.readonly && model.props.type.endsWith('pdf');
|
return !model.doc.readonly && model.props.type.endsWith('pdf');
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
export class AttachmentBlockComponent extends CaptionedBlockComponent<AttachmentBlockModel> {
|
export class AttachmentBlockComponent extends CaptionedBlockComponent<AttachmentBlockModel> {
|
||||||
@@ -61,18 +46,7 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
|
|
||||||
blockDraggable = true;
|
blockDraggable = true;
|
||||||
|
|
||||||
resourceController = new ResourceController(
|
blobState$ = signal<Partial<BlobState>>({});
|
||||||
computed(() => this.model.props.sourceId$.value)
|
|
||||||
);
|
|
||||||
|
|
||||||
get blobUrl() {
|
|
||||||
return this.resourceController.blobUrl$.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
get filetype() {
|
|
||||||
const name = this.model.props.name$.value;
|
|
||||||
return name.split('.').pop() ?? '';
|
|
||||||
}
|
|
||||||
|
|
||||||
protected containerStyleMap = styleMap({
|
protected containerStyleMap = styleMap({
|
||||||
position: 'relative',
|
position: 'relative',
|
||||||
@@ -84,12 +58,8 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
return this.std.get(FileSizeLimitProvider).maxFileSize;
|
return this.std.get(FileSizeLimitProvider).maxFileSize;
|
||||||
}
|
}
|
||||||
|
|
||||||
get citationService() {
|
|
||||||
return this.std.get(CitationProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isCitation() {
|
get isCitation() {
|
||||||
return this.citationService.isCitationModel(this.model);
|
return !!this.model.props.footnoteIdentifier;
|
||||||
}
|
}
|
||||||
|
|
||||||
convertTo = () => {
|
convertTo = () => {
|
||||||
@@ -99,7 +69,7 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
};
|
};
|
||||||
|
|
||||||
copy = () => {
|
copy = () => {
|
||||||
const slice = Slice.fromModels(this.store, [this.model]);
|
const slice = Slice.fromModels(this.doc, [this.model]);
|
||||||
this.std.clipboard.copySlice(slice).catch(console.error);
|
this.std.clipboard.copySlice(slice).catch(console.error);
|
||||||
toast(this.host, 'Copied to clipboard');
|
toast(this.host, 'Copied to clipboard');
|
||||||
};
|
};
|
||||||
@@ -123,60 +93,32 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
window.open(blobUrl, '_blank');
|
window.open(blobUrl, '_blank');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Refreshes data.
|
|
||||||
refreshData = () => {
|
refreshData = () => {
|
||||||
refreshData(this).catch(console.error);
|
refreshData(this.std, this).catch(console.error);
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _refreshKey$ = signal<string | null>(null);
|
updateBlobState(state: Partial<BlobState>) {
|
||||||
|
this.blobState$.value = { ...this.blobState$.value, ...state };
|
||||||
|
}
|
||||||
|
|
||||||
// Refreshes the embed component.
|
determineState = (
|
||||||
reload = () => {
|
loading: boolean,
|
||||||
batch(() => {
|
uploading: boolean,
|
||||||
if (this.model.props.embed$.value) {
|
overSize: boolean,
|
||||||
this._refreshKey$.value = nanoid();
|
error: boolean
|
||||||
return;
|
): State => {
|
||||||
}
|
if (overSize) return 'oversize';
|
||||||
|
if (error) return 'warning';
|
||||||
this.refreshData();
|
if (uploading) return 'uploading';
|
||||||
});
|
if (loading) return 'loading';
|
||||||
|
return 'none';
|
||||||
};
|
};
|
||||||
|
|
||||||
// Replaces the current attachment.
|
protected get embedView() {
|
||||||
replace = async () => {
|
return this.std
|
||||||
const state = this.resourceController.state$.peek();
|
.get(AttachmentEmbedProvider)
|
||||||
if (state.uploading) return;
|
.render(this.model, this.blobUrl ?? undefined, this._maxFileSize);
|
||||||
|
}
|
||||||
const file = await openSingleFileWith();
|
|
||||||
if (!file) return;
|
|
||||||
|
|
||||||
const sourceId = await this.std.store.blobSync.set(file);
|
|
||||||
const type = await getFileType(file);
|
|
||||||
const { name, size } = file;
|
|
||||||
|
|
||||||
let embed = this.model.props.embed$.value ?? false;
|
|
||||||
|
|
||||||
this.std.store.captureSync();
|
|
||||||
this.std.store.transact(() => {
|
|
||||||
this.std.store.updateBlock(this.blockId, {
|
|
||||||
name,
|
|
||||||
size,
|
|
||||||
type,
|
|
||||||
sourceId,
|
|
||||||
embed: false,
|
|
||||||
});
|
|
||||||
|
|
||||||
const provider = this.std.get(AttachmentEmbedProvider);
|
|
||||||
embed &&= provider.embedded(this.model);
|
|
||||||
|
|
||||||
if (embed) {
|
|
||||||
provider.convertTo(this.model);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reloads
|
|
||||||
this.reload();
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
private _selectBlock() {
|
private _selectBlock() {
|
||||||
const selectionManager = this.host.selection;
|
const selectionManager = this.host.selection;
|
||||||
@@ -186,59 +128,49 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
selectionManager.setGroup('note', [blockSelection]);
|
selectionManager.setGroup('note', [blockSelection]);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly _trackCitationDeleteEvent = () => {
|
|
||||||
// Check citation delete event
|
|
||||||
this._disposables.add(
|
|
||||||
this.std.store.slots.blockUpdated
|
|
||||||
.pipe(
|
|
||||||
filter(payload => {
|
|
||||||
if (!payload.isLocal) return false;
|
|
||||||
|
|
||||||
const { flavour, id, type } = payload;
|
|
||||||
if (
|
|
||||||
type !== 'delete' ||
|
|
||||||
flavour !== this.model.flavour ||
|
|
||||||
id !== this.model.id
|
|
||||||
)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
const { model } = payload;
|
|
||||||
if (!this.citationService.isCitationModel(model)) return false;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(() => {
|
|
||||||
this.citationService.trackEvent('Delete');
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
this.contentEditable = 'false';
|
this.contentEditable = 'false';
|
||||||
|
|
||||||
this.resourceController.setEngine(this.std.store.blobSync);
|
this.refreshData();
|
||||||
|
|
||||||
this.disposables.add(this.resourceController.subscribe());
|
|
||||||
this.disposables.add(this.resourceController);
|
|
||||||
|
|
||||||
this.disposables.add(
|
this.disposables.add(
|
||||||
this.model.props.sourceId$.subscribe(() => {
|
effect(() => {
|
||||||
this.refreshData();
|
const blobId = this.model.props.sourceId$.value;
|
||||||
|
if (!blobId) return;
|
||||||
|
|
||||||
|
const blobState$ = this.std.store.blobSync.blobState$(blobId);
|
||||||
|
if (!blobState$) return;
|
||||||
|
|
||||||
|
const subscription = blobState$.subscribe(state => {
|
||||||
|
if (state.overSize || state.errorMessage) {
|
||||||
|
state.uploading = false;
|
||||||
|
state.downloading = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.updateBlobState(state);
|
||||||
|
});
|
||||||
|
|
||||||
|
return () => subscription.unsubscribe();
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!this.model.props.style && !this.store.readonly) {
|
if (!this.model.props.style && !this.doc.readonly) {
|
||||||
this.store.withoutTransact(() => {
|
this.doc.withoutTransact(() => {
|
||||||
this.store.updateBlock(this.model, {
|
this.doc.updateBlock(this.model, {
|
||||||
style: AttachmentBlockStyles[1],
|
style: AttachmentBlockStyles[1],
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
this._trackCitationDeleteEvent();
|
override disconnectedCallback() {
|
||||||
|
const blobUrl = this.blobUrl;
|
||||||
|
if (blobUrl) {
|
||||||
|
URL.revokeObjectURL(blobUrl);
|
||||||
|
}
|
||||||
|
super.disconnectedCallback();
|
||||||
}
|
}
|
||||||
|
|
||||||
override firstUpdated() {
|
override firstUpdated() {
|
||||||
@@ -270,22 +202,6 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
@click=${(event: MouseEvent) => {
|
@click=${(event: MouseEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
onOverFileSize?.();
|
onOverFileSize?.();
|
||||||
|
|
||||||
{
|
|
||||||
const mode =
|
|
||||||
this.std.get(DocModeProvider).getEditorMode() ?? 'page';
|
|
||||||
const segment = mode === 'page' ? 'doc' : 'whiteboard';
|
|
||||||
this.std
|
|
||||||
.getOptional(TelemetryProvider)
|
|
||||||
?.track('AttachmentUpgradedEvent', {
|
|
||||||
segment,
|
|
||||||
page: `${segment} editor`,
|
|
||||||
module: 'attachment',
|
|
||||||
control: 'upgrade',
|
|
||||||
category: 'card',
|
|
||||||
type: this.model.props.name.split('.').pop() ?? '',
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
${UpgradeIcon()} Upgrade
|
${UpgradeIcon()} Upgrade
|
||||||
@@ -294,199 +210,150 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
protected renderNormalButton = (needUpload: boolean) => {
|
protected renderReloadButton = () => {
|
||||||
const label = needUpload ? 'retry' : 'reload';
|
|
||||||
const run = async () => {
|
|
||||||
if (needUpload) {
|
|
||||||
await this.resourceController.upload();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.refreshData();
|
|
||||||
};
|
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<button
|
<button
|
||||||
class="affine-attachment-content-button"
|
class="affine-attachment-content-button"
|
||||||
@click=${(event: MouseEvent) => {
|
@click=${(event: MouseEvent) => {
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
run().catch(console.error);
|
this.refreshData();
|
||||||
|
|
||||||
{
|
|
||||||
const mode =
|
|
||||||
this.std.get(DocModeProvider).getEditorMode() ?? 'page';
|
|
||||||
const segment = mode === 'page' ? 'doc' : 'whiteboard';
|
|
||||||
this.std
|
|
||||||
.getOptional(TelemetryProvider)
|
|
||||||
?.track('AttachmentReloadedEvent', {
|
|
||||||
segment,
|
|
||||||
page: `${segment} editor`,
|
|
||||||
module: 'attachment',
|
|
||||||
control: label,
|
|
||||||
category: 'card',
|
|
||||||
type: this.filetype,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
${ResetIcon()} ${label}
|
${ResetIcon()} Reload
|
||||||
</button>
|
</button>
|
||||||
`;
|
`;
|
||||||
};
|
};
|
||||||
|
|
||||||
protected renderWithHorizontal(
|
protected renderWithHorizontal(
|
||||||
classInfo: ClassInfo,
|
classInfo: ClassInfo,
|
||||||
{
|
icon: TemplateResult,
|
||||||
icon,
|
title: string,
|
||||||
title,
|
description: string,
|
||||||
description,
|
kind: TemplateResult,
|
||||||
kind,
|
state: State
|
||||||
state,
|
|
||||||
needUpload,
|
|
||||||
}: AttachmentResolvedStateInfo
|
|
||||||
) {
|
) {
|
||||||
return html`
|
return html`<div class=${classMap(classInfo)}>
|
||||||
<div class=${classMap(classInfo)}>
|
<div class="affine-attachment-content">
|
||||||
<div class="affine-attachment-content">
|
<div class="affine-attachment-content-title">
|
||||||
<div class="affine-attachment-content-title">
|
<div class="affine-attachment-content-title-icon">${icon}</div>
|
||||||
<div class="affine-attachment-content-title-icon">${icon}</div>
|
|
||||||
<div class="affine-attachment-content-title-text truncate">
|
|
||||||
${title}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="affine-attachment-content-description">
|
<div class="affine-attachment-content-title-text truncate">
|
||||||
<div class="affine-attachment-content-info truncate">
|
${title}
|
||||||
${description}
|
|
||||||
</div>
|
|
||||||
${choose(state, [
|
|
||||||
['error', () => this.renderNormalButton(needUpload)],
|
|
||||||
['error:oversize', this.renderUpgradeButton],
|
|
||||||
])}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="affine-attachment-banner">${kind}</div>
|
<div class="affine-attachment-content-description">
|
||||||
|
<div class="affine-attachment-content-info truncate">
|
||||||
|
${description}
|
||||||
|
</div>
|
||||||
|
${choose(state, [
|
||||||
|
['oversize', this.renderUpgradeButton],
|
||||||
|
['warning', this.renderReloadButton],
|
||||||
|
])}
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
|
||||||
|
<div class="affine-attachment-banner">${kind}</div>
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected renderWithVertical(
|
protected renderWithVertical(
|
||||||
classInfo: ClassInfo,
|
classInfo: ClassInfo,
|
||||||
{
|
icon: TemplateResult,
|
||||||
icon,
|
title: string,
|
||||||
title,
|
description: string,
|
||||||
description,
|
kind: TemplateResult,
|
||||||
kind,
|
state?: State
|
||||||
state,
|
|
||||||
needUpload,
|
|
||||||
}: AttachmentResolvedStateInfo
|
|
||||||
) {
|
) {
|
||||||
return html`
|
return html`<div class=${classMap(classInfo)}>
|
||||||
<div class=${classMap(classInfo)}>
|
<div class="affine-attachment-content">
|
||||||
<div class="affine-attachment-content">
|
<div class="affine-attachment-content-title">
|
||||||
<div class="affine-attachment-content-title">
|
<div class="affine-attachment-content-title-icon">${icon}</div>
|
||||||
<div class="affine-attachment-content-title-icon">${icon}</div>
|
|
||||||
<div class="affine-attachment-content-title-text truncate">
|
|
||||||
${title}
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="affine-attachment-content-info truncate">
|
<div class="affine-attachment-content-title-text truncate">
|
||||||
${description}
|
${title}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="affine-attachment-banner">
|
<div class="affine-attachment-content-info truncate">
|
||||||
${kind}
|
${description}
|
||||||
${choose(state, [
|
|
||||||
['error', () => this.renderNormalButton(needUpload)],
|
|
||||||
['error:oversize', this.renderUpgradeButton],
|
|
||||||
])}
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
|
||||||
|
<div class="affine-attachment-banner">
|
||||||
|
${kind}
|
||||||
|
${choose(state, [
|
||||||
|
['oversize', this.renderUpgradeButton],
|
||||||
|
['warning', this.renderReloadButton],
|
||||||
|
])}
|
||||||
|
</div>
|
||||||
|
</div>`;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected resolvedState$ = computed<AttachmentResolvedStateInfo>(() => {
|
protected renderCard = () => {
|
||||||
const size = this.model.props.size;
|
const { name, size, style } = this.model.props;
|
||||||
const name = this.model.props.name$.value;
|
const cardStyle = style ?? AttachmentBlockStyles[1];
|
||||||
const kind = getAttachmentFileIcon(this.filetype);
|
|
||||||
|
|
||||||
const resolvedState = this.resourceController.resolveStateWith({
|
const theme = this.std.get(ThemeProvider).theme$.value;
|
||||||
loadingIcon: LoadingIcon(),
|
const { LoadingIcon } = getEmbedCardIcons(theme);
|
||||||
errorIcon: WarningIcon(),
|
|
||||||
icon: AttachmentIcon(),
|
|
||||||
title: name,
|
|
||||||
description: formatSize(size),
|
|
||||||
});
|
|
||||||
|
|
||||||
return { ...resolvedState, kind };
|
const blobState = this.blobState$.value;
|
||||||
});
|
const {
|
||||||
|
uploading = false,
|
||||||
protected renderCardView = () => {
|
downloading = false,
|
||||||
const resolvedState = this.resolvedState$.value;
|
overSize = false,
|
||||||
const cardStyle = this.model.props.style$.value ?? AttachmentBlockStyles[1];
|
errorMessage,
|
||||||
|
} = blobState;
|
||||||
|
const warning = !overSize && Boolean(errorMessage);
|
||||||
|
const error = overSize || warning;
|
||||||
|
const loading = !error && downloading;
|
||||||
|
const state = this.determineState(loading, uploading, overSize, error);
|
||||||
|
|
||||||
const classInfo = {
|
const classInfo = {
|
||||||
'affine-attachment-card': true,
|
'affine-attachment-card': true,
|
||||||
[cardStyle]: true,
|
[cardStyle]: true,
|
||||||
loading: resolvedState.loading,
|
error,
|
||||||
error: resolvedState.error,
|
loading,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const icon = loading
|
||||||
|
? LoadingIcon
|
||||||
|
: error
|
||||||
|
? WarningIcon()
|
||||||
|
: AttachmentIcon();
|
||||||
|
const title = uploading ? 'Uploading...' : loading ? 'Loading...' : name;
|
||||||
|
const description = errorMessage || humanFileSize(size);
|
||||||
|
const kind = getAttachmentFileIcon(name.split('.').pop() ?? '');
|
||||||
|
|
||||||
return when(
|
return when(
|
||||||
cardStyle === 'cubeThick',
|
cardStyle === 'cubeThick',
|
||||||
() => this.renderWithVertical(classInfo, resolvedState),
|
() =>
|
||||||
() => this.renderWithHorizontal(classInfo, resolvedState)
|
this.renderWithVertical(
|
||||||
|
classInfo,
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
kind,
|
||||||
|
state
|
||||||
|
),
|
||||||
|
() =>
|
||||||
|
this.renderWithHorizontal(
|
||||||
|
classInfo,
|
||||||
|
icon,
|
||||||
|
title,
|
||||||
|
description,
|
||||||
|
kind,
|
||||||
|
state
|
||||||
|
)
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
protected renderEmbedView = () => {
|
|
||||||
const { model, blobUrl } = this;
|
|
||||||
if (!model.props.embed$.value || !blobUrl) return null;
|
|
||||||
|
|
||||||
const { std, _maxFileSize } = this;
|
|
||||||
const provider = std.get(AttachmentEmbedProvider);
|
|
||||||
|
|
||||||
const render = provider.getRender(model, _maxFileSize);
|
|
||||||
if (!render) return null;
|
|
||||||
|
|
||||||
const enabled = provider.shouldShowStatus(model);
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<div class="affine-attachment-embed-container">
|
|
||||||
${guard([this._refreshKey$.value], () => render(model, blobUrl))}
|
|
||||||
</div>
|
|
||||||
${when(enabled, () => {
|
|
||||||
const resolvedState = this.resolvedState$.value;
|
|
||||||
if (resolvedState.state !== 'error') return null;
|
|
||||||
// It should be an error messge.
|
|
||||||
const message = resolvedState.description;
|
|
||||||
if (!message) return null;
|
|
||||||
|
|
||||||
const needUpload = resolvedState.needUpload;
|
|
||||||
const action = () =>
|
|
||||||
needUpload ? this.resourceController.upload() : this.reload();
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<affine-resource-status
|
|
||||||
class="affine-attachment-embed-status"
|
|
||||||
.message=${message}
|
|
||||||
.needUpload=${needUpload}
|
|
||||||
.action=${action}
|
|
||||||
></affine-resource-status>
|
|
||||||
`;
|
|
||||||
})}
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly _renderCitation = () => {
|
private readonly _renderCitation = () => {
|
||||||
const { name, footnoteIdentifier } = this.model.props;
|
const { name, footnoteIdentifier } = this.model.props;
|
||||||
const icon = getAttachmentFileIcon(this.filetype);
|
const fileType = name.split('.').pop() ?? '';
|
||||||
|
const fileTypeIcon = getAttachmentFileIcon(fileType);
|
||||||
return html`<affine-citation-card
|
return html`<affine-citation-card
|
||||||
.icon=${icon}
|
.icon=${fileTypeIcon}
|
||||||
.citationTitle=${name}
|
.citationTitle=${name}
|
||||||
.citationIdentifier=${footnoteIdentifier}
|
.citationIdentifier=${footnoteIdentifier}
|
||||||
.active=${this.selected$.value}
|
.active=${this.selected$.value}
|
||||||
@@ -505,12 +372,23 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
|
|||||||
${when(
|
${when(
|
||||||
this.isCitation,
|
this.isCitation,
|
||||||
() => this._renderCitation(),
|
() => this._renderCitation(),
|
||||||
() => this.renderEmbedView() ?? this.renderCardView()
|
() =>
|
||||||
|
when(
|
||||||
|
this.embedView,
|
||||||
|
() =>
|
||||||
|
html`<div class="affine-attachment-embed-container">
|
||||||
|
${this.embedView}
|
||||||
|
</div>`,
|
||||||
|
this.renderCard
|
||||||
|
)
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
accessor blobUrl: string | null = null;
|
||||||
|
|
||||||
override accessor selectedStyle = SelectedStyle.Border;
|
override accessor selectedStyle = SelectedStyle.Border;
|
||||||
|
|
||||||
override accessor useCaptionEditor = true;
|
override accessor useCaptionEditor = true;
|
||||||
|
|||||||
@@ -1,14 +1,10 @@
|
|||||||
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
import { EdgelessLegacySlotIdentifier } from '@blocksuite/affine-block-surface';
|
||||||
import {
|
import { AttachmentBlockStyles } from '@blocksuite/affine-model';
|
||||||
AttachmentBlockSchema,
|
|
||||||
AttachmentBlockStyles,
|
|
||||||
} from '@blocksuite/affine-model';
|
|
||||||
import {
|
import {
|
||||||
EMBED_CARD_HEIGHT,
|
EMBED_CARD_HEIGHT,
|
||||||
EMBED_CARD_WIDTH,
|
EMBED_CARD_WIDTH,
|
||||||
} from '@blocksuite/affine-shared/consts';
|
} from '@blocksuite/affine-shared/consts';
|
||||||
import { toGfxBlockComponent } from '@blocksuite/std';
|
import { toGfxBlockComponent } from '@blocksuite/std';
|
||||||
import { GfxViewInteractionExtension } from '@blocksuite/std/gfx';
|
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
import { styleMap } from 'lit/directives/style-map.js';
|
||||||
|
|
||||||
import { AttachmentBlockComponent } from './attachment-block.js';
|
import { AttachmentBlockComponent } from './attachment-block.js';
|
||||||
@@ -52,21 +48,3 @@ declare global {
|
|||||||
'affine-edgeless-attachment': AttachmentEdgelessBlockComponent;
|
'affine-edgeless-attachment': AttachmentEdgelessBlockComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export const AttachmentBlockInteraction = GfxViewInteractionExtension(
|
|
||||||
AttachmentBlockSchema.model.flavour,
|
|
||||||
{
|
|
||||||
resizeConstraint: {
|
|
||||||
lockRatio: true,
|
|
||||||
},
|
|
||||||
handleRotate: () => {
|
|
||||||
return {
|
|
||||||
beforeRotate: context => {
|
|
||||||
context.set({
|
|
||||||
rotatable: false,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
import { AttachmentBlockSchema } from '@blocksuite/affine-model';
|
||||||
|
import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
||||||
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
|
||||||
|
import type { ExtensionType } from '@blocksuite/store';
|
||||||
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
|
import { AttachmentBlockAdapterExtensions } from './adapters/extension.js';
|
||||||
|
import { AttachmentDropOption } from './attachment-service.js';
|
||||||
|
import { attachmentSlashMenuConfig } from './configs/slash-menu.js';
|
||||||
|
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
||||||
|
import {
|
||||||
|
AttachmentEmbedConfigExtension,
|
||||||
|
AttachmentEmbedService,
|
||||||
|
} from './embed';
|
||||||
|
|
||||||
|
const flavour = AttachmentBlockSchema.model.flavour;
|
||||||
|
|
||||||
|
export const AttachmentBlockSpec: ExtensionType[] = [
|
||||||
|
FlavourExtension(flavour),
|
||||||
|
BlockViewExtension(flavour, model => {
|
||||||
|
return model.parent?.flavour === 'affine:surface'
|
||||||
|
? literal`affine-edgeless-attachment`
|
||||||
|
: literal`affine-attachment`;
|
||||||
|
}),
|
||||||
|
AttachmentDropOption,
|
||||||
|
AttachmentEmbedConfigExtension(),
|
||||||
|
AttachmentEmbedService,
|
||||||
|
AttachmentBlockAdapterExtensions,
|
||||||
|
createBuiltinToolbarConfigExtension(flavour),
|
||||||
|
SlashMenuConfigExtension(flavour, attachmentSlashMenuConfig),
|
||||||
|
].flat();
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
import { ConfirmIcon } from '@blocksuite/affine-components/icons';
|
import { ConfirmIcon } from '@blocksuite/affine-components/icons';
|
||||||
import { toast } from '@blocksuite/affine-components/toast';
|
import { toast } from '@blocksuite/affine-components/toast';
|
||||||
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
|
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
|
||||||
import { CitationProvider } from '@blocksuite/affine-shared/services';
|
|
||||||
import type { EditorHost } from '@blocksuite/std';
|
import type { EditorHost } from '@blocksuite/std';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { createRef, ref } from 'lit/directives/ref.js';
|
import { createRef, ref } from 'lit/directives/ref.js';
|
||||||
@@ -34,7 +33,6 @@ export const RenameModal = ({
|
|||||||
|
|
||||||
let fileName = includeExtension ? nameWithoutExtension : originalName;
|
let fileName = includeExtension ? nameWithoutExtension : originalName;
|
||||||
const extension = includeExtension ? originalExtension : '';
|
const extension = includeExtension ? originalExtension : '';
|
||||||
const citationService = editorHost.std.get(CitationProvider);
|
|
||||||
|
|
||||||
const abort = () => abortController.abort();
|
const abort = () => abortController.abort();
|
||||||
const onConfirm = () => {
|
const onConfirm = () => {
|
||||||
@@ -43,12 +41,9 @@ export const RenameModal = ({
|
|||||||
toast(editorHost, 'File name cannot be empty');
|
toast(editorHost, 'File name cannot be empty');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
model.store.updateBlock(model, {
|
model.doc.updateBlock(model, {
|
||||||
name: newFileName,
|
name: newFileName,
|
||||||
});
|
});
|
||||||
if (citationService.isCitationModel(model)) {
|
|
||||||
citationService.trackEvent('Edit');
|
|
||||||
}
|
|
||||||
abort();
|
abort();
|
||||||
};
|
};
|
||||||
const onInput = (e: InputEvent) => {
|
const onInput = (e: InputEvent) => {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { openSingleFileWith } from '@blocksuite/affine-shared/utils';
|
import { openFileOrFiles } from '@blocksuite/affine-shared/utils';
|
||||||
import { type SlashMenuConfig } from '@blocksuite/affine-widget-slash-menu';
|
import { type SlashMenuConfig } from '@blocksuite/affine-widget-slash-menu';
|
||||||
import { ExportToPdfIcon, FileIcon } from '@blocksuite/icons/lit';
|
import { ExportToPdfIcon, FileIcon } from '@blocksuite/icons/lit';
|
||||||
|
|
||||||
@@ -18,10 +18,10 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
|
|||||||
searchAlias: ['file'],
|
searchAlias: ['file'],
|
||||||
group: '4_Content & Media@3',
|
group: '4_Content & Media@3',
|
||||||
when: ({ model }) =>
|
when: ({ model }) =>
|
||||||
model.store.schema.flavourSchemaMap.has('affine:attachment'),
|
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
|
||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const file = await openSingleFileWith();
|
const file = await openFileOrFiles();
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
await addSiblingAttachmentBlocks(std, [file], model);
|
await addSiblingAttachmentBlocks(std, [file], model);
|
||||||
@@ -41,10 +41,10 @@ export const attachmentSlashMenuConfig: SlashMenuConfig = {
|
|||||||
},
|
},
|
||||||
group: '4_Content & Media@4',
|
group: '4_Content & Media@4',
|
||||||
when: ({ model }) =>
|
when: ({ model }) =>
|
||||||
model.store.schema.flavourSchemaMap.has('affine:attachment'),
|
model.doc.schema.flavourSchemaMap.has('affine:attachment'),
|
||||||
action: ({ std, model }) => {
|
action: ({ std, model }) => {
|
||||||
(async () => {
|
(async () => {
|
||||||
const file = await openSingleFileWith();
|
const file = await openFileOrFiles();
|
||||||
if (!file) return;
|
if (!file) return;
|
||||||
|
|
||||||
await addSiblingAttachmentBlocks(std, [file], model);
|
await addSiblingAttachmentBlocks(std, [file], model);
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ import {
|
|||||||
DownloadIcon,
|
DownloadIcon,
|
||||||
DuplicateIcon,
|
DuplicateIcon,
|
||||||
EditIcon,
|
EditIcon,
|
||||||
ReplaceIcon,
|
|
||||||
ResetIcon,
|
ResetIcon,
|
||||||
} from '@blocksuite/icons/lit';
|
} from '@blocksuite/icons/lit';
|
||||||
import { BlockFlavourIdentifier } from '@blocksuite/std';
|
import { BlockFlavourIdentifier } from '@blocksuite/std';
|
||||||
@@ -78,19 +77,13 @@ export const attachmentViewDropdownMenu = {
|
|||||||
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
||||||
if (!model) return;
|
if (!model) return;
|
||||||
|
|
||||||
const provider = ctx.std.get(AttachmentEmbedProvider);
|
if (!ctx.hasSelectedSurfaceModels) {
|
||||||
|
|
||||||
// TODO(@fundon): should auto focus image block.
|
|
||||||
if (
|
|
||||||
provider.shouldBeConverted(model) &&
|
|
||||||
!ctx.hasSelectedSurfaceModels
|
|
||||||
) {
|
|
||||||
// Clears
|
// Clears
|
||||||
ctx.reset();
|
ctx.reset();
|
||||||
ctx.select('note');
|
ctx.select('note');
|
||||||
}
|
}
|
||||||
|
|
||||||
provider.convertTo(model);
|
ctx.std.get(AttachmentEmbedProvider).convertTo(model);
|
||||||
|
|
||||||
ctx.track('SelectedView', {
|
ctx.track('SelectedView', {
|
||||||
...trackBaseProps,
|
...trackBaseProps,
|
||||||
@@ -101,32 +94,18 @@ export const attachmentViewDropdownMenu = {
|
|||||||
},
|
},
|
||||||
],
|
],
|
||||||
content(ctx) {
|
content(ctx) {
|
||||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
||||||
if (!block) return null;
|
if (!model) return null;
|
||||||
|
|
||||||
const model = block.model;
|
|
||||||
const embedProvider = ctx.std.get(AttachmentEmbedProvider);
|
const embedProvider = ctx.std.get(AttachmentEmbedProvider);
|
||||||
const actions = computed(() => {
|
const actions = this.actions.map(action => ({ ...action }));
|
||||||
const [cardAction, embedAction] = this.actions.map(action => ({
|
const viewType$ = computed(() => {
|
||||||
...action,
|
const [cardAction, embedAction] = actions;
|
||||||
}));
|
|
||||||
|
|
||||||
const ok = block.resourceController.resolvedState$.value.state === 'none';
|
|
||||||
const sourceId = Boolean(model.props.sourceId$.value);
|
|
||||||
const embed = model.props.embed$.value ?? false;
|
const embed = model.props.embed$.value ?? false;
|
||||||
// 1. Check whether `sourceId` exists.
|
|
||||||
// 2. Check if `embedded` is allowed.
|
|
||||||
// 3. Check `blobState$`
|
|
||||||
const allowed = ok && sourceId && embedProvider.embedded(model) && !embed;
|
|
||||||
|
|
||||||
cardAction.disabled = !embed;
|
cardAction.disabled = !embed;
|
||||||
embedAction.disabled = !allowed;
|
embedAction.disabled = embed && embedProvider.embedded(model);
|
||||||
|
|
||||||
return [cardAction, embedAction];
|
|
||||||
});
|
|
||||||
const viewType$ = computed(() => {
|
|
||||||
const [cardAction, embedAction] = actions.value;
|
|
||||||
const embed = model.props.embed$.value ?? false;
|
|
||||||
return embed ? embedAction.label : cardAction.label;
|
return embed ? embedAction.label : cardAction.label;
|
||||||
});
|
});
|
||||||
const onToggle = (e: CustomEvent<boolean>) => {
|
const onToggle = (e: CustomEvent<boolean>) => {
|
||||||
@@ -140,42 +119,27 @@ export const attachmentViewDropdownMenu = {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
return html`<affine-view-dropdown-menu
|
return html`${keyed(
|
||||||
@toggle=${onToggle}
|
model,
|
||||||
.actions=${actions.value}
|
html`<affine-view-dropdown-menu
|
||||||
.context=${ctx}
|
@toggle=${onToggle}
|
||||||
.viewType$=${viewType$}
|
.actions=${actions}
|
||||||
></affine-view-dropdown-menu>`;
|
.context=${ctx}
|
||||||
|
.viewType$=${viewType$}
|
||||||
|
></affine-view-dropdown-menu>`
|
||||||
|
)}`;
|
||||||
},
|
},
|
||||||
} as const satisfies ToolbarActionGroup<ToolbarAction>;
|
} as const satisfies ToolbarActionGroup<ToolbarAction>;
|
||||||
|
|
||||||
const replaceAction = {
|
|
||||||
id: 'c.replace',
|
|
||||||
tooltip: 'Replace attachment',
|
|
||||||
icon: ReplaceIcon(),
|
|
||||||
disabled(ctx) {
|
|
||||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
|
||||||
if (!block) return true;
|
|
||||||
|
|
||||||
const { downloading = false, uploading = false } =
|
|
||||||
block.resourceController.state$.value;
|
|
||||||
return downloading || uploading;
|
|
||||||
},
|
|
||||||
run(ctx) {
|
|
||||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
|
||||||
block?.replace().catch(console.error);
|
|
||||||
},
|
|
||||||
} as const satisfies ToolbarAction;
|
|
||||||
|
|
||||||
const downloadAction = {
|
const downloadAction = {
|
||||||
id: 'd.download',
|
id: 'c.download',
|
||||||
tooltip: 'Download',
|
tooltip: 'Download',
|
||||||
icon: DownloadIcon(),
|
icon: DownloadIcon(),
|
||||||
run(ctx) {
|
run(ctx) {
|
||||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
||||||
block?.download();
|
block?.download();
|
||||||
},
|
},
|
||||||
when(ctx) {
|
when: ctx => {
|
||||||
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
const model = ctx.getCurrentModelByType(AttachmentBlockModel);
|
||||||
if (!model) return false;
|
if (!model) return false;
|
||||||
// Current citation attachment block does not support download
|
// Current citation attachment block does not support download
|
||||||
@@ -184,7 +148,7 @@ const downloadAction = {
|
|||||||
} as const satisfies ToolbarAction;
|
} as const satisfies ToolbarAction;
|
||||||
|
|
||||||
const captionAction = {
|
const captionAction = {
|
||||||
id: 'e.caption',
|
id: 'd.caption',
|
||||||
tooltip: 'Caption',
|
tooltip: 'Caption',
|
||||||
icon: CaptionIcon(),
|
icon: CaptionIcon(),
|
||||||
run(ctx) {
|
run(ctx) {
|
||||||
@@ -237,7 +201,6 @@ const builtinToolbarConfig = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
attachmentViewDropdownMenu,
|
attachmentViewDropdownMenu,
|
||||||
replaceAction,
|
|
||||||
downloadAction,
|
downloadAction,
|
||||||
captionAction,
|
captionAction,
|
||||||
{
|
{
|
||||||
@@ -280,13 +243,7 @@ const builtinToolbarConfig = {
|
|||||||
icon: ResetIcon(),
|
icon: ResetIcon(),
|
||||||
run(ctx) {
|
run(ctx) {
|
||||||
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
const block = ctx.getCurrentBlockByType(AttachmentBlockComponent);
|
||||||
block?.reload();
|
block?.refreshData();
|
||||||
|
|
||||||
ctx.track('AttachmentReloadedEvent', {
|
|
||||||
...trackBaseProps,
|
|
||||||
control: 'reload',
|
|
||||||
type: block?.model.props.name.split('.').pop() ?? '',
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -371,17 +328,13 @@ const builtinSurfaceToolbarConfig = {
|
|||||||
)}`;
|
)}`;
|
||||||
},
|
},
|
||||||
} satisfies ToolbarActionGroup<ToolbarAction>,
|
} satisfies ToolbarActionGroup<ToolbarAction>,
|
||||||
{
|
|
||||||
...replaceAction,
|
|
||||||
id: 'd.replace',
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
...downloadAction,
|
...downloadAction,
|
||||||
id: 'e.download',
|
id: 'd.download',
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
...captionAction,
|
...captionAction,
|
||||||
id: 'f.caption',
|
id: 'e.caption',
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
when: ctx => ctx.getSurfaceModelsByType(AttachmentBlockModel).length === 1,
|
when: ctx => ctx.getSurfaceModelsByType(AttachmentBlockModel).length === 1,
|
||||||
|
|||||||
@@ -3,10 +3,6 @@ import {
|
|||||||
type ImageBlockProps,
|
type ImageBlockProps,
|
||||||
MAX_IMAGE_WIDTH,
|
MAX_IMAGE_WIDTH,
|
||||||
} from '@blocksuite/affine-model';
|
} from '@blocksuite/affine-model';
|
||||||
import {
|
|
||||||
EMBED_CARD_HEIGHT,
|
|
||||||
EMBED_CARD_WIDTH,
|
|
||||||
} from '@blocksuite/affine-shared/consts';
|
|
||||||
import { FileSizeLimitProvider } from '@blocksuite/affine-shared/services';
|
import { FileSizeLimitProvider } from '@blocksuite/affine-shared/services';
|
||||||
import {
|
import {
|
||||||
readImageSize,
|
readImageSize,
|
||||||
@@ -21,7 +17,6 @@ import type { ExtensionType } from '@blocksuite/store';
|
|||||||
import { Extension } from '@blocksuite/store';
|
import { Extension } from '@blocksuite/store';
|
||||||
import type { TemplateResult } from 'lit';
|
import type { TemplateResult } from 'lit';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { styleMap } from 'lit/directives/style-map.js';
|
|
||||||
|
|
||||||
import { getAttachmentBlob } from './utils';
|
import { getAttachmentBlob } from './utils';
|
||||||
|
|
||||||
@@ -39,22 +34,9 @@ export type AttachmentEmbedConfig = {
|
|||||||
std: BlockStdScope
|
std: BlockStdScope
|
||||||
) => Promise<void> | void;
|
) => Promise<void> | void;
|
||||||
/**
|
/**
|
||||||
* Renders the embed view.
|
* The template will be used to render the embed view.
|
||||||
*/
|
*/
|
||||||
render?: (
|
template?: (model: AttachmentBlockModel, blobUrl: string) => TemplateResult;
|
||||||
model: AttachmentBlockModel,
|
|
||||||
blobUrl: string
|
|
||||||
) => TemplateResult | null;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should show status when turned on.
|
|
||||||
*/
|
|
||||||
shouldShowStatus?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Should block type conversion be required.
|
|
||||||
*/
|
|
||||||
shouldBeConverted?: boolean;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Single embed config.
|
// Single embed config.
|
||||||
@@ -115,53 +97,39 @@ export class AttachmentEmbedService extends Extension {
|
|||||||
// Converts to embed view.
|
// Converts to embed view.
|
||||||
convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
convertTo(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
||||||
const config = this.values.find(config => config.check(model, maxFileSize));
|
const config = this.values.find(config => config.check(model, maxFileSize));
|
||||||
|
if (!config?.action) {
|
||||||
if (config?.action) {
|
model.doc.updateBlock(model, { embed: true });
|
||||||
config.action(model, this.std)?.catch(console.error);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
config.action(model, this.std)?.catch(console.error);
|
||||||
model.store.updateBlock(model, { embed: true });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
embedded(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
embedded(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
||||||
return this.values.some(config => config.check(model, maxFileSize));
|
return this.values.some(config => config.check(model, maxFileSize));
|
||||||
}
|
}
|
||||||
|
|
||||||
getRender(model: AttachmentBlockModel, maxFileSize = this._maxFileSize) {
|
render(
|
||||||
return (
|
|
||||||
this.values.find(config => config.check(model, maxFileSize))?.render ??
|
|
||||||
null
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldShowStatus(
|
|
||||||
model: AttachmentBlockModel,
|
model: AttachmentBlockModel,
|
||||||
|
blobUrl?: string,
|
||||||
maxFileSize = this._maxFileSize
|
maxFileSize = this._maxFileSize
|
||||||
) {
|
) {
|
||||||
return (
|
if (!model.props.embed || !blobUrl) return;
|
||||||
this.values.find(config => config.check(model, maxFileSize))
|
|
||||||
?.shouldShowStatus ?? false
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
shouldBeConverted(
|
const config = this.values.find(config => config.check(model, maxFileSize));
|
||||||
model: AttachmentBlockModel,
|
if (!config || !config.template) {
|
||||||
maxFileSize = this._maxFileSize
|
console.error('No embed view template found!', model, model.props.type);
|
||||||
) {
|
return;
|
||||||
return (
|
}
|
||||||
this.values.find(config => config.check(model, maxFileSize))
|
|
||||||
?.shouldBeConverted ?? false
|
return config.template(model, blobUrl);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const embedConfig: AttachmentEmbedConfig[] = [
|
const embedConfig: AttachmentEmbedConfig[] = [
|
||||||
{
|
{
|
||||||
name: 'image',
|
name: 'image',
|
||||||
shouldBeConverted: true,
|
|
||||||
check: model =>
|
check: model =>
|
||||||
model.store.schema.flavourSchemaMap.has('affine:image') &&
|
model.doc.schema.flavourSchemaMap.has('affine:image') &&
|
||||||
model.props.type.startsWith('image/'),
|
model.props.type.startsWith('image/'),
|
||||||
async action(model, std) {
|
async action(model, std) {
|
||||||
const component = std.view.getBlock(model.id);
|
const component = std.view.getBlock(model.id);
|
||||||
@@ -172,30 +140,16 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'pdf',
|
name: 'pdf',
|
||||||
shouldShowStatus: true,
|
|
||||||
check: (model, maxFileSize) =>
|
check: (model, maxFileSize) =>
|
||||||
model.props.type === 'application/pdf' && model.props.size <= maxFileSize,
|
model.props.type === 'application/pdf' && model.props.size <= maxFileSize,
|
||||||
action: model => {
|
template: (_, blobUrl) => {
|
||||||
const bound = Bound.deserialize(model.props.xywh);
|
|
||||||
bound.w = EMBED_CARD_WIDTH.pdf;
|
|
||||||
bound.h = EMBED_CARD_HEIGHT.pdf;
|
|
||||||
model.store.updateBlock(model, {
|
|
||||||
embed: true,
|
|
||||||
style: 'pdf',
|
|
||||||
xywh: bound.serialize(),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
render: (_, blobUrl) => {
|
|
||||||
// More options: https://tinytip.co/tips/html-pdf-params/
|
// More options: https://tinytip.co/tips/html-pdf-params/
|
||||||
// https://chromium.googlesource.com/chromium/src/+/refs/tags/121.0.6153.1/chrome/browser/resources/pdf/open_pdf_params_parser.ts
|
// https://chromium.googlesource.com/chromium/src/+/refs/tags/121.0.6153.1/chrome/browser/resources/pdf/open_pdf_params_parser.ts
|
||||||
const parameters = '#toolbar=0';
|
const parameters = '#toolbar=0';
|
||||||
return html`
|
return html`
|
||||||
<iframe
|
<iframe
|
||||||
style=${styleMap({
|
style="width: 100%; color-scheme: auto;"
|
||||||
width: '100%',
|
height="480"
|
||||||
minHeight: '480px',
|
|
||||||
colorScheme: 'auto',
|
|
||||||
})}
|
|
||||||
src=${blobUrl + parameters}
|
src=${blobUrl + parameters}
|
||||||
loading="lazy"
|
loading="lazy"
|
||||||
scrolling="no"
|
scrolling="no"
|
||||||
@@ -203,7 +157,6 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
|||||||
allowTransparency
|
allowTransparency
|
||||||
allowfullscreen
|
allowfullscreen
|
||||||
type="application/pdf"
|
type="application/pdf"
|
||||||
credentialless
|
|
||||||
></iframe>
|
></iframe>
|
||||||
<div class="affine-attachment-embed-event-mask"></div>
|
<div class="affine-attachment-embed-event-mask"></div>
|
||||||
`;
|
`;
|
||||||
@@ -211,44 +164,23 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'video',
|
name: 'video',
|
||||||
shouldShowStatus: true,
|
|
||||||
check: (model, maxFileSize) =>
|
check: (model, maxFileSize) =>
|
||||||
model.props.type.startsWith('video/') && model.props.size <= maxFileSize,
|
model.props.type.startsWith('video/') && model.props.size <= maxFileSize,
|
||||||
action: model => {
|
template: (_, blobUrl) =>
|
||||||
const bound = Bound.deserialize(model.props.xywh);
|
|
||||||
bound.w = EMBED_CARD_WIDTH.video;
|
|
||||||
bound.h = EMBED_CARD_HEIGHT.video;
|
|
||||||
model.store.updateBlock(model, {
|
|
||||||
embed: true,
|
|
||||||
style: 'video',
|
|
||||||
xywh: bound.serialize(),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
render: (_, blobUrl) =>
|
|
||||||
html`<video
|
html`<video
|
||||||
style=${styleMap({
|
style="max-height: max-content;"
|
||||||
display: 'flex',
|
width="100%;"
|
||||||
objectFit: 'cover',
|
height="480"
|
||||||
backgroundSize: 'cover',
|
|
||||||
width: '100%',
|
|
||||||
height: '100%',
|
|
||||||
})}
|
|
||||||
src=${blobUrl}
|
|
||||||
width="100%"
|
|
||||||
height="100%"
|
|
||||||
controls
|
controls
|
||||||
|
src=${blobUrl}
|
||||||
></video>`,
|
></video>`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: 'audio',
|
name: 'audio',
|
||||||
check: (model, maxFileSize) =>
|
check: (model, maxFileSize) =>
|
||||||
model.props.type.startsWith('audio/') && model.props.size <= maxFileSize,
|
model.props.type.startsWith('audio/') && model.props.size <= maxFileSize,
|
||||||
render: (_, blobUrl) =>
|
template: (_, blobUrl) =>
|
||||||
html`<audio
|
html`<audio controls src=${blobUrl} style="margin: 4px;"></audio>`,
|
||||||
style=${styleMap({ margin: '4px' })}
|
|
||||||
src=${blobUrl}
|
|
||||||
controls
|
|
||||||
></audio>`,
|
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
@@ -256,7 +188,7 @@ const embedConfig: AttachmentEmbedConfig[] = [
|
|||||||
* Turn the attachment block into an image block.
|
* Turn the attachment block into an image block.
|
||||||
*/
|
*/
|
||||||
async function turnIntoImageBlock(model: AttachmentBlockModel) {
|
async function turnIntoImageBlock(model: AttachmentBlockModel) {
|
||||||
if (!model.store.schema.flavourSchemaMap.has('affine:image')) {
|
if (!model.doc.schema.flavourSchemaMap.has('affine:image')) {
|
||||||
console.error('The image flavour is not supported!');
|
console.error('The image flavour is not supported!');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
export * from './adapters';
|
export * from './adapters';
|
||||||
export * from './attachment-block';
|
export * from './attachment-block';
|
||||||
export * from './attachment-service';
|
export * from './attachment-service';
|
||||||
|
export * from './attachment-spec';
|
||||||
export { attachmentViewDropdownMenu } from './configs/toolbar';
|
export { attachmentViewDropdownMenu } from './configs/toolbar';
|
||||||
export * from './edgeless-clipboard-config';
|
export * from './edgeless-clipboard-config';
|
||||||
export {
|
export {
|
||||||
|
|||||||
@@ -6,9 +6,9 @@ export const styles = css`
|
|||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
user-select: none;
|
user-select: none;
|
||||||
overflow: hidden;
|
|
||||||
border: 1px solid ${unsafeCSSVarV2('layer/background/tertiary')};
|
border: 1px solid ${unsafeCSSVarV2('layer/background/tertiary')};
|
||||||
background: ${unsafeCSSVarV2('layer/background/primary')};
|
background: ${unsafeCSSVarV2('layer/background/primary')};
|
||||||
|
overflow: hidden;
|
||||||
|
|
||||||
&.focused {
|
&.focused {
|
||||||
border-color: ${unsafeCSSVarV2('layer/insideBorder/primaryBorder')};
|
border-color: ${unsafeCSSVarV2('layer/insideBorder/primaryBorder')};
|
||||||
@@ -30,13 +30,6 @@ export const styles = css`
|
|||||||
min-width: 0;
|
min-width: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.truncate {
|
|
||||||
align-self: stretch;
|
|
||||||
text-overflow: ellipsis;
|
|
||||||
white-space: nowrap;
|
|
||||||
overflow: hidden;
|
|
||||||
}
|
|
||||||
|
|
||||||
.affine-attachment-content-title {
|
.affine-attachment-content-title {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
@@ -47,10 +40,18 @@ export const styles = css`
|
|||||||
|
|
||||||
.affine-attachment-content-title-icon {
|
.affine-attachment-content-title-icon {
|
||||||
display: flex;
|
display: flex;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
color: var(--affine-text-primary-color);
|
color: var(--affine-text-primary-color);
|
||||||
font-size: 16px;
|
}
|
||||||
|
|
||||||
|
.truncate {
|
||||||
|
align-self: stretch;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.affine-attachment-content-title-text {
|
.affine-attachment-content-title-text {
|
||||||
@@ -91,7 +92,6 @@ export const styles = css`
|
|||||||
font-size: var(--affine-font-xs);
|
font-size: var(--affine-font-xs);
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: 500;
|
font-weight: 500;
|
||||||
text-transform: capitalize;
|
|
||||||
line-height: 20px;
|
line-height: 20px;
|
||||||
|
|
||||||
svg {
|
svg {
|
||||||
@@ -107,7 +107,7 @@ export const styles = css`
|
|||||||
|
|
||||||
.affine-attachment-card.loading {
|
.affine-attachment-card.loading {
|
||||||
.affine-attachment-content-title-text {
|
.affine-attachment-content-title-text {
|
||||||
color: ${unsafeCSSVarV2('text/placeholder')};
|
color: var(--affine-placeholder-color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,11 +117,6 @@ export const styles = css`
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.affine-attachment-card.loading,
|
|
||||||
.affine-attachment-card.error {
|
|
||||||
background: ${unsafeCSSVarV2('layer/background/secondary')};
|
|
||||||
}
|
|
||||||
|
|
||||||
.affine-attachment-card.cubeThick {
|
.affine-attachment-card.cubeThick {
|
||||||
flex-direction: column-reverse;
|
flex-direction: column-reverse;
|
||||||
|
|
||||||
@@ -143,12 +138,6 @@ export const styles = css`
|
|||||||
height: 100%;
|
height: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
.affine-attachment-embed-status {
|
|
||||||
position: absolute;
|
|
||||||
left: 14px;
|
|
||||||
bottom: 64px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.affine-attachment-embed-event-mask {
|
.affine-attachment-embed-event-mask {
|
||||||
position: absolute;
|
position: absolute;
|
||||||
inset: 0;
|
inset: 0;
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import {
|
|||||||
FileSizeLimitProvider,
|
FileSizeLimitProvider,
|
||||||
TelemetryProvider,
|
TelemetryProvider,
|
||||||
} from '@blocksuite/affine-shared/services';
|
} from '@blocksuite/affine-shared/services';
|
||||||
import { formatSize } from '@blocksuite/affine-shared/utils';
|
import { humanFileSize } from '@blocksuite/affine-shared/utils';
|
||||||
import { Bound, type IVec, Vec } from '@blocksuite/global/gfx';
|
import { Bound, type IVec, Vec } from '@blocksuite/global/gfx';
|
||||||
import type { BlockStdScope } from '@blocksuite/std';
|
import type { BlockStdScope } from '@blocksuite/std';
|
||||||
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
import { GfxControllerIdentifier } from '@blocksuite/std/gfx';
|
||||||
@@ -22,13 +22,15 @@ import type { BlockModel } from '@blocksuite/store';
|
|||||||
import type { AttachmentBlockComponent } from './attachment-block';
|
import type { AttachmentBlockComponent } from './attachment-block';
|
||||||
|
|
||||||
export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
||||||
const { sourceId$, type$ } = model.props;
|
const {
|
||||||
const sourceId = sourceId$.peek();
|
sourceId$: { value: sourceId },
|
||||||
const type = type$.peek();
|
type$: { value: type },
|
||||||
|
} = model.props;
|
||||||
if (!sourceId) return null;
|
if (!sourceId) return null;
|
||||||
|
|
||||||
const doc = model.store;
|
const doc = model.doc;
|
||||||
const blob = await doc.blobSync.get(sourceId);
|
let blob = await doc.blobSync.get(sourceId);
|
||||||
|
|
||||||
if (!blob) return null;
|
if (!blob) return null;
|
||||||
|
|
||||||
return new Blob([blob], { type });
|
return new Blob([blob], { type });
|
||||||
@@ -39,9 +41,9 @@ export async function getAttachmentBlob(model: AttachmentBlockModel) {
|
|||||||
* the download process may take a long time!
|
* the download process may take a long time!
|
||||||
*/
|
*/
|
||||||
export function downloadAttachmentBlob(block: AttachmentBlockComponent) {
|
export function downloadAttachmentBlob(block: AttachmentBlockComponent) {
|
||||||
const { host, model, blobUrl, resourceController } = block;
|
const { host, model, blobUrl, blobState$ } = block;
|
||||||
|
|
||||||
if (resourceController.state$.peek().downloading) {
|
if (blobState$.peek().downloading) {
|
||||||
toast(host, 'Download in progress...');
|
toast(host, 'Download in progress...');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -54,7 +56,7 @@ export function downloadAttachmentBlob(block: AttachmentBlockComponent) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
resourceController.updateState({ downloading: true });
|
block.updateBlobState({ downloading: true });
|
||||||
|
|
||||||
toast(host, `Downloading ${shortName}`);
|
toast(host, `Downloading ${shortName}`);
|
||||||
|
|
||||||
@@ -65,14 +67,34 @@ export function downloadAttachmentBlob(block: AttachmentBlockComponent) {
|
|||||||
tmpLink.dispatchEvent(event);
|
tmpLink.dispatchEvent(event);
|
||||||
tmpLink.remove();
|
tmpLink.remove();
|
||||||
|
|
||||||
resourceController.updateState({ downloading: false });
|
block.updateBlobState({ downloading: false });
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function refreshData(block: AttachmentBlockComponent) {
|
export async function refreshData(
|
||||||
|
std: BlockStdScope,
|
||||||
|
block: AttachmentBlockComponent
|
||||||
|
) {
|
||||||
const model = block.model;
|
const model = block.model;
|
||||||
|
const sourceId = model.props.sourceId$.peek();
|
||||||
|
if (!sourceId) return;
|
||||||
|
|
||||||
|
const blobUrl = block.blobUrl;
|
||||||
|
if (blobUrl) {
|
||||||
|
URL.revokeObjectURL(blobUrl);
|
||||||
|
block.blobUrl = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
let blob = await std.store.blobSync.get(sourceId);
|
||||||
|
if (!blob) {
|
||||||
|
block.updateBlobState({ errorMessage: 'File not found' });
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const type = model.props.type$.peek();
|
const type = model.props.type$.peek();
|
||||||
|
|
||||||
await block.resourceController.refreshUrlWith(type);
|
blob = new Blob([blob], { type });
|
||||||
|
|
||||||
|
block.blobUrl = URL.createObjectURL(blob);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function getFileType(file: File) {
|
export async function getFileType(file: File) {
|
||||||
@@ -82,7 +104,7 @@ export async function getFileType(file: File) {
|
|||||||
const buffer = await file.arrayBuffer();
|
const buffer = await file.arrayBuffer();
|
||||||
const FileType = await import('file-type');
|
const FileType = await import('file-type');
|
||||||
const fileType = await FileType.fileTypeFromBuffer(buffer);
|
const fileType = await FileType.fileTypeFromBuffer(buffer);
|
||||||
return fileType?.mime ?? '';
|
return fileType ? fileType.mime : '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function hasExceeded(
|
function hasExceeded(
|
||||||
@@ -93,7 +115,7 @@ function hasExceeded(
|
|||||||
const exceeded = files.some(file => file.size > maxFileSize);
|
const exceeded = files.some(file => file.size > maxFileSize);
|
||||||
|
|
||||||
if (exceeded) {
|
if (exceeded) {
|
||||||
const size = formatSize(maxFileSize);
|
const size = humanFileSize(maxFileSize, true, 0);
|
||||||
toast(std.host, `You can only upload files less than ${size}`);
|
toast(std.host, `You can only upload files less than ${size}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,7 +152,7 @@ async function buildPropsWith(
|
|||||||
std.getOptional(TelemetryProvider)?.track('AttachmentUploadedEvent', {
|
std.getOptional(TelemetryProvider)?.track('AttachmentUploadedEvent', {
|
||||||
page: `${mode} editor`,
|
page: `${mode} editor`,
|
||||||
module: 'attachment',
|
module: 'attachment',
|
||||||
segment: mode,
|
segment: 'attachment',
|
||||||
control: 'uploader',
|
control: 'uploader',
|
||||||
type,
|
type,
|
||||||
category,
|
category,
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import { SlashMenuConfigExtension } from '@blocksuite/affine-widget-slash-menu';
|
|||||||
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
|
import { BlockViewExtension, FlavourExtension } from '@blocksuite/std';
|
||||||
import { literal } from 'lit/static-html.js';
|
import { literal } from 'lit/static-html.js';
|
||||||
|
|
||||||
import { AttachmentBlockInteraction } from './attachment-edgeless-block.js';
|
|
||||||
import { AttachmentDropOption } from './attachment-service.js';
|
import { AttachmentDropOption } from './attachment-service.js';
|
||||||
import { attachmentSlashMenuConfig } from './configs/slash-menu.js';
|
import { attachmentSlashMenuConfig } from './configs/slash-menu.js';
|
||||||
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
import { createBuiltinToolbarConfigExtension } from './configs/toolbar';
|
||||||
@@ -45,7 +44,6 @@ export class AttachmentViewExtension extends ViewExtensionProvider {
|
|||||||
]);
|
]);
|
||||||
if (this.isEdgeless(context.scope)) {
|
if (this.isEdgeless(context.scope)) {
|
||||||
context.register(EdgelessClipboardAttachmentConfig);
|
context.register(EdgelessClipboardAttachmentConfig);
|
||||||
context.register(AttachmentBlockInteraction);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
},
|
},
|
||||||
"include": ["./src"],
|
"include": ["./src"],
|
||||||
"references": [
|
"references": [
|
||||||
|
{ "path": "../embed" },
|
||||||
{ "path": "../surface" },
|
{ "path": "../surface" },
|
||||||
{ "path": "../../components" },
|
{ "path": "../../components" },
|
||||||
{ "path": "../../ext-loader" },
|
{ "path": "../../ext-loader" },
|
||||||
|
|||||||
@@ -11,7 +11,6 @@
|
|||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@blocksuite/affine-block-embed": "workspace:*",
|
"@blocksuite/affine-block-embed": "workspace:*",
|
||||||
"@blocksuite/affine-block-embed-doc": "workspace:*",
|
|
||||||
"@blocksuite/affine-block-surface": "workspace:*",
|
"@blocksuite/affine-block-surface": "workspace:*",
|
||||||
"@blocksuite/affine-components": "workspace:*",
|
"@blocksuite/affine-components": "workspace:*",
|
||||||
"@blocksuite/affine-ext-loader": "workspace:*",
|
"@blocksuite/affine-ext-loader": "workspace:*",
|
||||||
@@ -24,7 +23,7 @@
|
|||||||
"@blocksuite/store": "workspace:*",
|
"@blocksuite/store": "workspace:*",
|
||||||
"@lit/context": "^1.1.2",
|
"@lit/context": "^1.1.2",
|
||||||
"@preact/signals-core": "^1.8.0",
|
"@preact/signals-core": "^1.8.0",
|
||||||
"@toeverything/theme": "^1.1.15",
|
"@toeverything/theme": "^1.1.12",
|
||||||
"lit": "^3.2.0",
|
"lit": "^3.2.0",
|
||||||
"minimatch": "^10.0.1",
|
"minimatch": "^10.0.1",
|
||||||
"rxjs": "^7.8.1",
|
"rxjs": "^7.8.1",
|
||||||
@@ -32,10 +31,11 @@
|
|||||||
"zod": "^3.23.8"
|
"zod": "^3.23.8"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"vitest": "3.1.3"
|
"vitest": "3.1.1"
|
||||||
},
|
},
|
||||||
"exports": {
|
"exports": {
|
||||||
".": "./src/index.ts",
|
".": "./src/index.ts",
|
||||||
|
"./effects": "./src/effects.ts",
|
||||||
"./store": "./src/store.ts",
|
"./store": "./src/store.ts",
|
||||||
"./view": "./src/view.ts"
|
"./view": "./src/view.ts"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -140,16 +140,4 @@ Some text in between
|
|||||||
`.trim();
|
`.trim();
|
||||||
expect(footnoteUrlPreprocessor(input)).toBe(expected);
|
expect(footnoteUrlPreprocessor(input)).toBe(expected);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should encode partial encoded URLs in footnote definitions', () => {
|
|
||||||
const input = `
|
|
||||||
[^ref]: {"type":"url","url":"https://zh.wikipedia.org/zh-hans/%E5%B0%8F%E7%B1%B3SU7"}
|
|
||||||
[^ref2]: {"type":"url","url":"https://www.dw.com/zh/%E5%B0%8F%E7%B1%B3%E9%A6%96%E6%AC%BE%E6%B1%BD%E8%BD%A6%E5%8F%91%E5%B8%83-su7%E8%B5%B7%E4%BB%B72159%E4%B8%87%E5%85%83/a-68693432"}
|
|
||||||
`.trim();
|
|
||||||
const expected = `
|
|
||||||
[^ref]: {"type":"url","url":"https%3A%2F%2Fzh.wikipedia.org%2Fzh-hans%2F%25E5%25B0%258F%25E7%25B1%25B3SU7"}
|
|
||||||
[^ref2]: {"type":"url","url":"https%3A%2F%2Fwww.dw.com%2Fzh%2F%25E5%25B0%258F%25E7%25B1%25B3%25E9%25A6%2596%25E6%25AC%25BE%25E6%25B1%25BD%25E8%25BD%25A6%25E5%258F%2591%25E5%25B8%2583-su7%25E8%25B5%25B7%25E4%25BB%25B72159%25E4%25B8%2587%25E5%2585%2583%2Fa-68693432"}
|
|
||||||
`.trim();
|
|
||||||
expect(footnoteUrlPreprocessor(input)).toBe(expected);
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
isFootnoteDefinitionNode,
|
isFootnoteDefinitionNode,
|
||||||
type MarkdownAST,
|
type MarkdownAST,
|
||||||
} from '@blocksuite/affine-shared/adapters';
|
} from '@blocksuite/affine-shared/adapters';
|
||||||
|
import { FeatureFlagService } from '@blocksuite/affine-shared/services';
|
||||||
import { nanoid } from '@blocksuite/store';
|
import { nanoid } from '@blocksuite/store';
|
||||||
|
|
||||||
const isUrlFootnoteDefinitionNode = (node: MarkdownAST) => {
|
const isUrlFootnoteDefinitionNode = (node: MarkdownAST) => {
|
||||||
@@ -32,7 +33,15 @@ export const bookmarkBlockMarkdownAdapterMatcher =
|
|||||||
toMatch: o => isUrlFootnoteDefinitionNode(o.node),
|
toMatch: o => isUrlFootnoteDefinitionNode(o.node),
|
||||||
toBlockSnapshot: {
|
toBlockSnapshot: {
|
||||||
enter: (o, context) => {
|
enter: (o, context) => {
|
||||||
if (!isFootnoteDefinitionNode(o.node)) {
|
const { provider } = context;
|
||||||
|
let enableCitation = false;
|
||||||
|
try {
|
||||||
|
const featureFlagService = provider?.get(FeatureFlagService);
|
||||||
|
enableCitation = !!featureFlagService?.getFlag('enable_citation');
|
||||||
|
} catch {
|
||||||
|
enableCitation = false;
|
||||||
|
}
|
||||||
|
if (!isFootnoteDefinitionNode(o.node) || !enableCitation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,17 +23,12 @@ type FootnoteDefinition = {
|
|||||||
content: FootNoteReferenceParams;
|
content: FootNoteReferenceParams;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
// Check if a URL is already encoded with encodeURIComponent
|
||||||
* Check if a URL is already encoded with encodeURIComponent to avoid markdown link parsing
|
function isEncoded(uri: string): boolean {
|
||||||
* @example
|
|
||||||
* https://example.com/path%20with%20spaces should return false
|
|
||||||
* https://example.com/ should return false
|
|
||||||
* https%3A%2F%2Fexample.com%2F should return true
|
|
||||||
*/
|
|
||||||
function isFullyEncoded(uri: string): boolean {
|
|
||||||
try {
|
try {
|
||||||
// Should check if the components of the URI are fully encoded
|
// If decoding produces a different result than the original,
|
||||||
return uri === encodeURIComponent(decodeURIComponent(uri));
|
// then the URI contains encoded characters
|
||||||
|
return uri !== decodeURIComponent(uri);
|
||||||
} catch {
|
} catch {
|
||||||
// If decoding fails, the URI contains invalid percent-encoding
|
// If decoding fails, the URI contains invalid percent-encoding
|
||||||
return true;
|
return true;
|
||||||
@@ -199,10 +194,10 @@ class FootnoteParser {
|
|||||||
// Process URLs in footnote content
|
// Process URLs in footnote content
|
||||||
private processUrls(footnote: FootnoteDefinition): FootnoteDefinition {
|
private processUrls(footnote: FootnoteDefinition): FootnoteDefinition {
|
||||||
const content = footnote.content;
|
const content = footnote.content;
|
||||||
if (content.url && !isFullyEncoded(content.url)) {
|
if (content.url && !isEncoded(content.url)) {
|
||||||
content.url = encodeURIComponent(content.url);
|
content.url = encodeURIComponent(content.url);
|
||||||
}
|
}
|
||||||
if (content.favicon && !isFullyEncoded(content.favicon)) {
|
if (content.favicon && !isEncoded(content.favicon)) {
|
||||||
content.favicon = encodeURIComponent(content.favicon);
|
content.favicon = encodeURIComponent(content.favicon);
|
||||||
}
|
}
|
||||||
return footnote;
|
return footnote;
|
||||||
|
|||||||
@@ -2,24 +2,14 @@ import {
|
|||||||
CaptionedBlockComponent,
|
CaptionedBlockComponent,
|
||||||
SelectedStyle,
|
SelectedStyle,
|
||||||
} from '@blocksuite/affine-components/caption';
|
} from '@blocksuite/affine-components/caption';
|
||||||
import type {
|
import type { BookmarkBlockModel } from '@blocksuite/affine-model';
|
||||||
BookmarkBlockModel,
|
import { DocModeProvider } from '@blocksuite/affine-shared/services';
|
||||||
LinkPreviewData,
|
|
||||||
} from '@blocksuite/affine-model';
|
|
||||||
import { ImageProxyService } from '@blocksuite/affine-shared/adapters';
|
|
||||||
import {
|
|
||||||
CitationProvider,
|
|
||||||
DocModeProvider,
|
|
||||||
LinkPreviewServiceIdentifier,
|
|
||||||
} from '@blocksuite/affine-shared/services';
|
|
||||||
import { normalizeUrl } from '@blocksuite/affine-shared/utils';
|
|
||||||
import { BlockSelection } from '@blocksuite/std';
|
import { BlockSelection } from '@blocksuite/std';
|
||||||
import { computed, type ReadonlySignal, signal } from '@preact/signals-core';
|
import { computed, type ReadonlySignal } from '@preact/signals-core';
|
||||||
import { html } from 'lit';
|
import { html } from 'lit';
|
||||||
import { property, query } from 'lit/decorators.js';
|
import { property, query } from 'lit/decorators.js';
|
||||||
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
|
||||||
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
|
||||||
import { filter } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import { refreshBookmarkUrlData } from './utils.js';
|
import { refreshBookmarkUrlData } from './utils.js';
|
||||||
|
|
||||||
@@ -38,62 +28,6 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
|
|
||||||
protected containerStyleMap!: ReturnType<typeof styleMap>;
|
protected containerStyleMap!: ReturnType<typeof styleMap>;
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Local link preview data
|
|
||||||
* When the doc is in readonly mode, and the link preview data are not provided (stored in the block model),
|
|
||||||
* We will use the local link preview data fetched from the link previewer service to render the block.
|
|
||||||
*/
|
|
||||||
private readonly _localLinkPreview$ = signal<LinkPreviewData>({
|
|
||||||
icon: null,
|
|
||||||
title: null,
|
|
||||||
description: null,
|
|
||||||
image: null,
|
|
||||||
});
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @description Link preview data for actual rendering
|
|
||||||
* When the doc is not in readonly mode, and the link preview data are provided (stored in the block model),
|
|
||||||
* We will use the model props to render the block.
|
|
||||||
* Otherwise, we will use the local link preview data to render the block.
|
|
||||||
*/
|
|
||||||
linkPreview$ = computed(() => {
|
|
||||||
const modelProps = this.model.props;
|
|
||||||
const local = this._localLinkPreview$.value;
|
|
||||||
return {
|
|
||||||
icon: modelProps.icon$.value ?? local.icon ?? null,
|
|
||||||
title: modelProps.title$.value ?? local.title ?? null,
|
|
||||||
description: modelProps.description$.value ?? local.description ?? null,
|
|
||||||
image: modelProps.image$.value ?? local.image ?? null,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
private readonly _updateLocalLinkPreview = () => {
|
|
||||||
// cancel any inflight request
|
|
||||||
this._fetchAbortController?.abort();
|
|
||||||
this._fetchAbortController = new AbortController();
|
|
||||||
|
|
||||||
this.loading = true;
|
|
||||||
this.error = false;
|
|
||||||
|
|
||||||
this.std
|
|
||||||
.get(LinkPreviewServiceIdentifier)
|
|
||||||
.query(this.model.props.url, this._fetchAbortController.signal)
|
|
||||||
.then(data => {
|
|
||||||
this._localLinkPreview$.value = {
|
|
||||||
icon: data.icon ?? null,
|
|
||||||
title: data.title ?? null,
|
|
||||||
description: data.description ?? null,
|
|
||||||
image: data.image ?? null,
|
|
||||||
};
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
this.error = true;
|
|
||||||
})
|
|
||||||
.finally(() => {
|
|
||||||
this.loading = false;
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
selectBlock = () => {
|
selectBlock = () => {
|
||||||
const selectionManager = this.std.selection;
|
const selectionManager = this.std.selection;
|
||||||
const blockSelection = selectionManager.create(BlockSelection, {
|
const blockSelection = selectionManager.create(BlockSelection, {
|
||||||
@@ -102,12 +36,12 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
selectionManager.setGroup('note', [blockSelection]);
|
selectionManager.setGroup('note', [blockSelection]);
|
||||||
};
|
};
|
||||||
|
|
||||||
get link() {
|
|
||||||
return normalizeUrl(this.model.props.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
open = () => {
|
open = () => {
|
||||||
window.open(this.link, '_blank');
|
let link = this.model.props.url;
|
||||||
|
if (!link.match(/^[a-zA-Z]+:\/\//)) {
|
||||||
|
link = 'https://' + link;
|
||||||
|
}
|
||||||
|
window.open(link, '_blank');
|
||||||
};
|
};
|
||||||
|
|
||||||
refreshData = () => {
|
refreshData = () => {
|
||||||
@@ -116,46 +50,24 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
get citationService() {
|
|
||||||
return this.std.get(CitationProvider);
|
|
||||||
}
|
|
||||||
|
|
||||||
get isCitation() {
|
get isCitation() {
|
||||||
return this.citationService.isCitationModel(this.model);
|
return (
|
||||||
|
!!this.model.props.footnoteIdentifier &&
|
||||||
|
this.model.props.style === 'citation'
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
get imageProxyService() {
|
|
||||||
return this.std.get(ImageProxyService);
|
|
||||||
}
|
|
||||||
|
|
||||||
handleClick = (event: MouseEvent) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
|
|
||||||
if (
|
|
||||||
this.model.parent?.flavour !== 'affine:surface' &&
|
|
||||||
!this.store.readonly
|
|
||||||
) {
|
|
||||||
this.selectBlock();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
handleDoubleClick = (event: MouseEvent) => {
|
|
||||||
event.stopPropagation();
|
|
||||||
this.open();
|
|
||||||
};
|
|
||||||
|
|
||||||
private readonly _renderCitationView = () => {
|
private readonly _renderCitationView = () => {
|
||||||
const { url, footnoteIdentifier } = this.model.props;
|
const { title, description, url, icon, footnoteIdentifier } =
|
||||||
const { icon, title, description } = this.linkPreview$.value;
|
this.model.props;
|
||||||
const iconSrc = icon ? this.imageProxyService.buildUrl(icon) : undefined;
|
|
||||||
return html`
|
return html`
|
||||||
<affine-citation-card
|
<affine-citation-card
|
||||||
.icon=${iconSrc}
|
.icon=${icon}
|
||||||
.citationTitle=${title || url}
|
.citationTitle=${title || url}
|
||||||
.citationContent=${description}
|
.citationContent=${description}
|
||||||
.citationIdentifier=${footnoteIdentifier}
|
.citationIdentifier=${footnoteIdentifier}
|
||||||
.onClickCallback=${this.handleClick}
|
.onClickCallback=${this.selectBlock}
|
||||||
.onDoubleClickCallback=${this.handleDoubleClick}
|
.onDoubleClickCallback=${this.open}
|
||||||
.active=${this.selected$.value}
|
.active=${this.selected$.value}
|
||||||
></affine-citation-card>
|
></affine-citation-card>
|
||||||
`;
|
`;
|
||||||
@@ -169,31 +81,6 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
></bookmark-card>`;
|
></bookmark-card>`;
|
||||||
};
|
};
|
||||||
|
|
||||||
private readonly _trackCitationDeleteEvent = () => {
|
|
||||||
// Check citation delete event
|
|
||||||
this._disposables.add(
|
|
||||||
this.std.store.slots.blockUpdated
|
|
||||||
.pipe(
|
|
||||||
filter(payload => {
|
|
||||||
if (!payload.isLocal) return false;
|
|
||||||
const { flavour, id, type } = payload;
|
|
||||||
if (
|
|
||||||
type !== 'delete' ||
|
|
||||||
flavour !== this.model.flavour ||
|
|
||||||
id !== this.model.id
|
|
||||||
)
|
|
||||||
return false;
|
|
||||||
const { model } = payload;
|
|
||||||
if (!this.citationService.isCitationModel(model)) return false;
|
|
||||||
return true;
|
|
||||||
})
|
|
||||||
)
|
|
||||||
.subscribe(() => {
|
|
||||||
this.citationService.trackEvent('Delete');
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
||||||
override connectedCallback() {
|
override connectedCallback() {
|
||||||
super.connectedCallback();
|
super.connectedCallback();
|
||||||
|
|
||||||
@@ -210,17 +97,10 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
|
|
||||||
this.contentEditable = 'false';
|
this.contentEditable = 'false';
|
||||||
|
|
||||||
if (
|
if (!this.model.props.description && !this.model.props.title) {
|
||||||
(!this.model.props.description && !this.model.props.title) ||
|
if (this.doc.readonly) {
|
||||||
(!this.model.props.image && this.model.props.style === 'vertical')
|
|
||||||
) {
|
|
||||||
// When the doc is readonly, and the preview data not provided
|
|
||||||
// We should fetch the preview data and update the local link preview data
|
|
||||||
if (this.store.readonly) {
|
|
||||||
this._updateLocalLinkPreview();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Otherwise, we should refresh the data to the model props
|
|
||||||
this.refreshData();
|
this.refreshData();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -231,8 +111,6 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
this._trackCitationDeleteEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override disconnectedCallback(): void {
|
override disconnectedCallback(): void {
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user