Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@blocksuite/affine-shared

Package Overview
Dependencies
Maintainers
0
Versions
213
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blocksuite/affine-shared - npm Package Compare versions

Comparing version 0.17.9 to 0.17.10

20

CHANGELOG.md
# @blocksuite/affine-shared
## 0.17.10
### Patch Changes
- e0d0016: - Fix database performance issue
- Fix frame panel display issue
- Fix editor settings for color with transparency
- Fix portal in modals
- Fix group selection rendering delay
- Remove unused and duplicated code
- Improve frame model
- Improve ParseDocUrl service
- Support custom max zoom
- Updated dependencies [e0d0016]
- @blocksuite/affine-model@0.17.10
- @blocksuite/block-std@0.17.10
- @blocksuite/global@0.17.10
- @blocksuite/inline@0.17.10
- @blocksuite/store@0.17.10
## 0.17.9

@@ -4,0 +24,0 @@

4

dist/services/edit-props-store.d.ts

@@ -1,6 +0,6 @@

import { NodePropsSchema } from '@blocksuite/affine-shared/utils';
import { type BlockStdScope, LifeCycleWatcher } from '@blocksuite/block-std';
import { Slot } from '@blocksuite/global/utils';
import { type Signal } from '@lit-labs/preact-signals';
import { type Signal } from '@preact/signals-core';
import { z } from 'zod';
import { NodePropsSchema } from '../utils/index.js';
export type LastProps = z.infer<typeof NodePropsSchema>;

@@ -7,0 +7,0 @@ export type LastPropsKey = keyof LastProps;

@@ -1,12 +0,11 @@

import { ColorSchema, NodePropsSchema } from '@blocksuite/affine-shared/utils';
import { LifeCycleWatcher } from '@blocksuite/block-std';
import { DisposableGroup, Slot, } from '@blocksuite/global/utils';
import { computed, signal } from '@lit-labs/preact-signals';
import { computed, signal } from '@preact/signals-core';
import clonedeep from 'lodash.clonedeep';
import isPlainObject from 'lodash.isplainobject';
import merge from 'lodash.merge';
import mergeWith from 'lodash.mergewith';
import { z } from 'zod';
import { ColorSchema, makeDeepOptional, NodePropsSchema, } from '../utils/index.js';
import { EditorSettingProvider } from './editor-setting-service.js';
const LastPropsSchema = NodePropsSchema;
const SESSION_PROP_KEY = 'blocksuite:prop:record';
const OptionalPropsSchema = makeDeepOptional(NodePropsSchema);
const SessionPropsSchema = z.object({

@@ -42,2 +41,8 @@ viewport: z.union([

}
function customizer(_target, source) {
if (ColorSchema.safeParse(source).success) {
return source;
}
return;
}
export class EditPropsStore extends LifeCycleWatcher {

@@ -58,12 +63,6 @@ static { this.key = 'EditPropsStore'; }

}, {}));
const props = sessionStorage.getItem(SESSION_PROP_KEY);
if (props) {
const result = LastPropsSchema.safeParse(JSON.parse(props));
if (result.success) {
merge(clonedeep(initProps), result.data);
}
}
this.lastProps$ = computed(() => {
const editorSetting$ = this.std.getOptional(EditorSettingProvider);
return merge(clonedeep(initProps), editorSetting$?.value, this.innerProps$.value);
const nextProps = mergeWith(clonedeep(initProps), editorSetting$?.value, this.innerProps$.value, customizer);
return LastPropsSchema.parse(nextProps);
});

@@ -99,3 +98,3 @@ }

const lastProps = this.lastProps$.value[key];
return merge(clonedeep(lastProps), props);
return mergeWith(clonedeep(lastProps), props, customizer);
}

@@ -126,9 +125,9 @@ dispose() {

recordLastProps(key, props) {
const overrideProps = extractProps(props, LastPropsSchema.shape[key]._def.innerType);
const schema = OptionalPropsSchema._def.innerType.shape[key];
const overrideProps = schema.parse(props);
if (Object.keys(overrideProps).length === 0)
return;
const innerProps = this.innerProps$.value;
this.innerProps$.value = merge(clonedeep(innerProps), {
[key]: overrideProps,
});
const nextProps = mergeWith(clonedeep(innerProps), { [key]: overrideProps }, customizer);
this.innerProps$.value = OptionalPropsSchema.parse(nextProps);
}

@@ -147,34 +146,2 @@ setStorage(key, value) {

}
function extractProps(props, ref) {
const result = {};
Object.entries(props).forEach(([key, value]) => {
if (!(key in ref.shape))
return;
if (isPlainObject(value)) {
if (isColorType(key, value)) {
const color = processColorValue(value);
if (Object.keys(color).length === 0)
return;
result[key] = color;
return;
}
result[key] = extractProps(props[key], ref.shape[key]);
}
else {
result[key] = value;
}
});
return result;
}
function isColorType(key, value) {
return (['background', 'color', 'stroke', 'fill', 'Color'].some(stuff => key.startsWith(stuff) || key.endsWith(stuff)) && ColorSchema.safeParse(value).success);
}
// Don't want the user to create a transparent element, so the alpha value is removed.
function processColorValue(value) {
const obj = {};
for (const [k, v] of Object.entries(value)) {
obj[k] = v.startsWith('#') ? v.substring(0, 7) : v;
}
return obj;
}
//# sourceMappingURL=edit-props-store.js.map

@@ -0,8 +1,7 @@

import type { ReferenceParams } from '@blocksuite/affine-model';
import type { ExtensionType } from '@blocksuite/block-std';
export interface ParseDocUrlService {
parseDocUrl: (url: string) => {
parseDocUrl: (url: string) => ({
docId: string;
blockIds?: string[];
elementIds?: string[];
} | undefined;
} & ReferenceParams) | undefined;
}

@@ -9,0 +8,0 @@ export declare const ParseDocUrlProvider: import("@blocksuite/global/di").ServiceIdentifier<ParseDocUrlService> & ((variant: import("@blocksuite/global/di").ServiceVariant) => import("@blocksuite/global/di").ServiceIdentifier<ParseDocUrlService>);

import { ColorScheme } from '@blocksuite/affine-model';
import { signal } from '@lit-labs/preact-signals';
import { signal } from '@preact/signals-core';
const TRANSPARENT = 'transparent';

@@ -58,18 +58,19 @@ /**

: fallback;
let result;
if (typeof color === 'string') {
return ((color.startsWith('--')
? color.endsWith(TRANSPARENT)
? TRANSPARENT
: `var(${color})`
: color) ?? fallback);
result = color;
}
if (!color) {
else if (color.light && color.dark) {
result = this.mode === ColorScheme.Dark ? color.dark : color.light;
}
else if (color.normal) {
result = color.normal;
}
if (!result) {
return fallback;
}
if (color.light && color.dark) {
return this.mode === ColorScheme.Dark
? `var(${color.dark})`
: `var(${color.light})`;
if (result.startsWith('--')) {
return result.endsWith(TRANSPARENT) ? TRANSPARENT : `var(${result})`;
}
return color.normal ?? fallback;
return result;
}

@@ -76,0 +77,0 @@ /**

@@ -86,3 +86,4 @@ import { IS_IOS, IS_MAC } from '@blocksuite/global/env';

latestArgs = args;
raqId && cancelAnimationFrame(raqId);
if (raqId)
return;
raqId = requestConnectedFrame(() => {

@@ -89,0 +90,0 @@ raqId = undefined;

@@ -11,3 +11,3 @@ interface Observable<T> {

};
export { type Signal } from '@lit-labs/preact-signals';
export { type Signal } from '@preact/signals-core';
//# sourceMappingURL=signal.d.ts.map

@@ -1,2 +0,2 @@

import { signal } from '@lit-labs/preact-signals';
import { signal } from '@preact/signals-core';
export function createSignalFromObservable(observable$, initValue) {

@@ -12,3 +12,3 @@ const newSignal = signal(initValue);

}
export {} from '@lit-labs/preact-signals';
export {} from '@preact/signals-core';
//# sourceMappingURL=signal.js.map
import { ConnectorMode, DEFAULT_CONNECTOR_COLOR, DEFAULT_CONNECTOR_TEXT_COLOR, DEFAULT_FRONT_END_POINT_STYLE, DEFAULT_NOTE_BACKGROUND_COLOR, DEFAULT_NOTE_BORDER_SIZE, DEFAULT_NOTE_BORDER_STYLE, DEFAULT_NOTE_CORNER, DEFAULT_NOTE_SHADOW, DEFAULT_REAR_END_POINT_STYLE, DEFAULT_ROUGHNESS, DEFAULT_SHAPE_FILL_COLOR, DEFAULT_SHAPE_STROKE_COLOR, DEFAULT_SHAPE_TEXT_COLOR, DEFAULT_TEXT_COLOR, FillColorsSchema, FontFamily, FontStyle, FontWeight, FrameBackgroundColorsSchema, LayoutType, LineColor, LineColorsSchema, LineWidth, MindmapStyle, NoteBackgroundColorsSchema, NoteDisplayMode, NoteShadowsSchema, PointStyle, ShapeStyle, StrokeColorsSchema, StrokeStyle, TextAlign, TextVerticalAlign, } from '@blocksuite/affine-model';
import { z } from 'zod';
import { z, ZodDefault, ZodObject, ZodUnion } from 'zod';
const ConnectorEndpointSchema = z.nativeEnum(PointStyle);

@@ -47,3 +47,3 @@ const StrokeStyleSchema = z.nativeEnum(StrokeStyle);

labelStyle: z.object({
color: LineColorSchema,
color: TextColorSchema,
fontSize: z.number(),

@@ -209,2 +209,20 @@ fontFamily: FontFamilySchema,

});
export function makeDeepOptional(schema) {
if (schema instanceof ZodDefault) {
return makeDeepOptional(schema._def.innerType);
}
if (schema instanceof ZodObject) {
const shape = schema.shape;
const deepOptionalShape = Object.fromEntries(Object.entries(shape).map(([key, value]) => {
return [key, makeDeepOptional(value)];
}));
return z.object(deepOptionalShape).optional();
}
else if (schema instanceof ZodUnion) {
return schema.or(z.undefined());
}
else {
return schema.optional();
}
}
//# sourceMappingURL=zod-schema.js.map
{
"name": "@blocksuite/affine-shared",
"version": "0.17.9",
"version": "0.17.10",
"description": "Default BlockSuite editable blocks.",

@@ -18,12 +18,14 @@ "type": "module",

"dependencies": {
"@blocksuite/affine-model": "0.17.9",
"@blocksuite/block-std": "0.17.9",
"@blocksuite/global": "0.17.9",
"@blocksuite/inline": "0.17.9",
"@blocksuite/store": "0.17.9",
"@blocksuite/affine-model": "0.17.10",
"@blocksuite/block-std": "0.17.10",
"@blocksuite/global": "0.17.10",
"@blocksuite/inline": "0.17.10",
"@blocksuite/store": "0.17.10",
"@floating-ui/dom": "^1.6.10",
"@lit-labs/preact-signals": "^1.0.2",
"@lit/context": "^1.1.2",
"@preact/signals-core": "^1.8.0",
"@toeverything/theme": "^1.0.8",
"lit": "^3.2.0",
"lodash.clonedeep": "^4.5.0",
"lodash.mergewith": "^4.6.2",
"minimatch": "^10.0.1",

@@ -127,4 +129,8 @@ "zod": "^3.23.8"

],
"devDependencies": {
"@types/lodash.clonedeep": "^4.5.9",
"@types/lodash.mergewith": "^4"
},
"main": "dist/index.js",
"types": "dist/index.d.ts"
}

@@ -1,2 +0,1 @@

import { ColorSchema, NodePropsSchema } from '@blocksuite/affine-shared/utils';
import { type BlockStdScope, LifeCycleWatcher } from '@blocksuite/block-std';

@@ -8,16 +7,19 @@ import {

} from '@blocksuite/global/utils';
import { computed, type Signal, signal } from '@lit-labs/preact-signals';
import { computed, type Signal, signal } from '@preact/signals-core';
import clonedeep from 'lodash.clonedeep';
import isPlainObject from 'lodash.isplainobject';
import merge from 'lodash.merge';
import mergeWith from 'lodash.mergewith';
import { z } from 'zod';
import {
ColorSchema,
makeDeepOptional,
NodePropsSchema,
} from '../utils/index.js';
import { EditorSettingProvider } from './editor-setting-service.js';
const LastPropsSchema = NodePropsSchema;
const OptionalPropsSchema = makeDeepOptional(NodePropsSchema);
export type LastProps = z.infer<typeof NodePropsSchema>;
export type LastPropsKey = keyof LastProps;
const SESSION_PROP_KEY = 'blocksuite:prop:record';
const SessionPropsSchema = z.object({

@@ -63,2 +65,9 @@ viewport: z.union([

function customizer(_target: unknown, source: unknown) {
if (ColorSchema.safeParse(source).success) {
return source;
}
return;
}
export class EditPropsStore extends LifeCycleWatcher {

@@ -91,17 +100,11 @@ static override key = 'EditPropsStore';

const props = sessionStorage.getItem(SESSION_PROP_KEY);
if (props) {
const result = LastPropsSchema.safeParse(JSON.parse(props));
if (result.success) {
merge(clonedeep(initProps), result.data);
}
}
this.lastProps$ = computed(() => {
const editorSetting$ = this.std.getOptional(EditorSettingProvider);
return merge(
const nextProps = mergeWith(
clonedeep(initProps),
editorSetting$?.value,
this.innerProps$.value
this.innerProps$.value,
customizer
);
return LastPropsSchema.parse(nextProps);
});

@@ -140,3 +143,3 @@ }

const lastProps = this.lastProps$.value[key];
return merge(clonedeep(lastProps), props);
return mergeWith(clonedeep(lastProps), props, customizer);
}

@@ -170,12 +173,13 @@

recordLastProps(key: LastPropsKey, props: Partial<LastProps[LastPropsKey]>) {
const overrideProps = extractProps(
props,
LastPropsSchema.shape[key]._def.innerType
);
const schema = OptionalPropsSchema._def.innerType.shape[key];
const overrideProps = schema.parse(props);
if (Object.keys(overrideProps).length === 0) return;
const innerProps = this.innerProps$.value;
this.innerProps$.value = merge(clonedeep(innerProps), {
[key]: overrideProps,
});
const nextProps = mergeWith(
clonedeep(innerProps),
{ [key]: overrideProps },
customizer
);
this.innerProps$.value = OptionalPropsSchema.parse(nextProps);
}

@@ -198,46 +202,1 @@

}
function extractProps(
props: Record<string, unknown>,
ref: z.ZodObject<z.ZodRawShape>
): Record<string, unknown> {
const result: Record<string, unknown> = {};
Object.entries(props).forEach(([key, value]) => {
if (!(key in ref.shape)) return;
if (isPlainObject(value)) {
if (isColorType(key, value)) {
const color = processColorValue(value as z.infer<typeof ColorSchema>);
if (Object.keys(color).length === 0) return;
result[key] = color;
return;
}
result[key] = extractProps(
props[key] as Record<string, unknown>,
ref.shape[key] as z.ZodObject<z.ZodRawShape>
);
} else {
result[key] = value;
}
});
return result;
}
function isColorType(key: string, value: unknown) {
return (
['background', 'color', 'stroke', 'fill', 'Color'].some(
stuff => key.startsWith(stuff) || key.endsWith(stuff)
) && ColorSchema.safeParse(value).success
);
}
// Don't want the user to create a transparent element, so the alpha value is removed.
function processColorValue(value: z.infer<typeof ColorSchema>) {
const obj: Record<string, string> = {};
for (const [k, v] of Object.entries(value)) {
obj[k] = v.startsWith('#') ? v.substring(0, 7) : v;
}
return obj;
}
import type { ExtensionType } from '@blocksuite/block-std';
import type { DeepPartial } from '@blocksuite/global/utils';
import type { Signal } from '@lit-labs/preact-signals';
import type { Signal } from '@preact/signals-core';
import type { z } from 'zod';

@@ -5,0 +5,0 @@

@@ -0,1 +1,2 @@

import type { ReferenceParams } from '@blocksuite/affine-model';
import type { ExtensionType } from '@blocksuite/block-std';

@@ -6,9 +7,5 @@

export interface ParseDocUrlService {
parseDocUrl: (url: string) =>
| {
docId: string;
blockIds?: string[];
elementIds?: string[];
}
| undefined;
parseDocUrl: (
url: string
) => ({ docId: string } & ReferenceParams) | undefined;
}

@@ -15,0 +12,0 @@

import { type Color, ColorScheme } from '@blocksuite/affine-model';
import { signal } from '@lit-labs/preact-signals';
import { signal } from '@preact/signals-core';

@@ -67,23 +67,20 @@ const TRANSPARENT = 'transparent';

let result: string | undefined;
if (typeof color === 'string') {
return (
(color.startsWith('--')
? color.endsWith(TRANSPARENT)
? TRANSPARENT
: `var(${color})`
: color) ?? fallback
);
result = color;
} else if (color.light && color.dark) {
result = this.mode === ColorScheme.Dark ? color.dark : color.light;
} else if (color.normal) {
result = color.normal;
}
if (!color) {
if (!result) {
return fallback;
}
if (color.light && color.dark) {
return this.mode === ColorScheme.Dark
? `var(${color.dark})`
: `var(${color.light})`;
if (result.startsWith('--')) {
return result.endsWith(TRANSPARENT) ? TRANSPARENT : `var(${result})`;
}
return color.normal ?? fallback;
return result;
}

@@ -90,0 +87,0 @@

@@ -180,3 +180,3 @@ import { IS_IOS, IS_MAC } from '@blocksuite/global/env';

raqId && cancelAnimationFrame(raqId);
if (raqId) return;

@@ -183,0 +183,0 @@ raqId = requestConnectedFrame(() => {

@@ -1,2 +0,2 @@

import { signal } from '@lit-labs/preact-signals';
import { signal } from '@preact/signals-core';

@@ -25,2 +25,2 @@ interface Observable<T> {

export { type Signal } from '@lit-labs/preact-signals';
export { type Signal } from '@preact/signals-core';

@@ -37,3 +37,3 @@ import {

} from '@blocksuite/affine-model';
import { z } from 'zod';
import { z, ZodDefault, ZodObject, type ZodTypeAny, ZodUnion } from 'zod';

@@ -86,3 +86,3 @@ const ConnectorEndpointSchema = z.nativeEnum(PointStyle);

labelStyle: z.object({
color: LineColorSchema,
color: TextColorSchema,
fontSize: z.number(),

@@ -261,1 +261,20 @@ fontFamily: FontFamilySchema,

export type NodeProps = z.infer<typeof NodePropsSchema>;
export function makeDeepOptional(schema: ZodTypeAny): ZodTypeAny {
if (schema instanceof ZodDefault) {
return makeDeepOptional(schema._def.innerType);
}
if (schema instanceof ZodObject) {
const shape = schema.shape;
const deepOptionalShape = Object.fromEntries(
Object.entries(shape).map(([key, value]) => {
return [key, makeDeepOptional(value as ZodTypeAny)];
})
);
return z.object(deepOptionalShape).optional();
} else if (schema instanceof ZodUnion) {
return schema.or(z.undefined());
} else {
return schema.optional();
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc