Skip to content

Commit

Permalink
Add missing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
cocopon committed Jun 20, 2023
1 parent 3d0bbfb commit 24f8990
Show file tree
Hide file tree
Showing 12 changed files with 45 additions and 34 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/blade/common/api/rack-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function createApi(
});

const pool = config.pool ?? createDefaultPluginPool();
pool.register(TestValueBladePlugin);
pool.register('test', TestValueBladePlugin);

return new RackApi(c, pool);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blade/folder/api/folder-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createApi(opt_doc?: Document): FolderApi {
viewProps: ViewProps.create(),
});
const pool = createDefaultPluginPool();
pool.register(TestValueBladePlugin);
pool.register('test', TestValueBladePlugin);
return new FolderApi(c, pool);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/blade/tab/api/tab-page-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function createApi() {
viewProps: ViewProps.create(),
});
const pool = createDefaultPluginPool();
pool.register(TestValueBladePlugin);
pool.register('test', TestValueBladePlugin);
return new TabPageApi(c, pool);
}

Expand Down
7 changes: 5 additions & 2 deletions packages/core/src/common/tp-error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,14 @@ export class TpError<T extends ErrorType> {
});
}

public static notCompatible(id: string): TpError<'notcompatible'> {
public static notCompatible(
bundleId: string,
id: string,
): TpError<'notcompatible'> {
return new TpError({
type: 'notcompatible',
context: {
id: id,
id: `${bundleId}.${id}`,
},
});
}
Expand Down
5 changes: 0 additions & 5 deletions packages/core/src/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ export interface BasePlugin {
*/
type: PluginType;

/**
* The custom CSS for the plugin.
*/
css?: string;

/**
* The version of the core used for this plugin.
*/
Expand Down
22 changes: 21 additions & 1 deletion packages/core/src/plugin/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,29 @@ export type TpPlugin =

export type TpPluginBundle =
| {
/**
* The custom CSS for the bundle.
*/
css?: string;

/**
* The identifier of the bundle.
*/
id: string;

plugin: TpPlugin;
}
| {
/**
* The custom CSS for the bundle.
*/
css?: string;

/**
* The identifier of the bundle.
*/
id: string;

plugins: TpPlugin[];
};

Expand Down Expand Up @@ -57,7 +77,7 @@ export function createDefaultPluginPool(): PluginPool {
FolderBladePlugin,
TabBladePlugin,
].forEach((p) => {
pool.register(p);
pool.register('core', p);
});
return pool;
}
4 changes: 2 additions & 2 deletions packages/core/src/plugin/pool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ export class PluginPool {
];
}

public register(r: TpPlugin): void {
public register(bundleId: string, r: TpPlugin): void {
if (!isCompatible(r.core)) {
throw TpError.notCompatible(r.id);
throw TpError.notCompatible(bundleId, r.id);
}

if (r.type === 'blade') {
Expand Down
2 changes: 1 addition & 1 deletion packages/tweakpane/src/main/ts/blade/list/plugin-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {ListBladeParams, ListBladePlugin} from './plugin.js';

function createPluginPool(): PluginPool {
const pool = createDefaultPluginPool();
pool.register(ListBladePlugin);
pool.register('test', ListBladePlugin);
return pool;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tweakpane/src/main/ts/blade/slider/plugin-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {SliderBladeParams, SliderBladePlugin} from './plugin.js';

function createPluginPool(): PluginPool {
const pool = createDefaultPluginPool();
pool.register(SliderBladePlugin);
pool.register('test', SliderBladePlugin);
return pool;
}

Expand Down
2 changes: 1 addition & 1 deletion packages/tweakpane/src/main/ts/blade/text/plugin-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import {TextBladeParams, TextBladePlugin} from './plugin.js';

function createPluginPool(): PluginPool {
const pool = createDefaultPluginPool();
pool.register(TextBladePlugin);
pool.register('test', TextBladePlugin);
return pool;
}

Expand Down
5 changes: 3 additions & 2 deletions packages/tweakpane/src/main/ts/pane/pane-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ describe(Pane.name, () => {
document: doc,
});
assert.notStrictEqual(
doc.querySelector('style[data-tp-style=default]'),
doc.querySelector('style[data-tp-style=plugin-default]'),
null,
);
});
Expand All @@ -92,10 +92,11 @@ describe(Pane.name, () => {
document: doc,
});
pane.registerPlugin({
id: 'test',
css: css,
plugin: {
id: 'test',
type: 'input',
css: css,
core: VERSION,
accept: (value, params) => {
if (typeof value !== 'string') {
Expand Down
24 changes: 8 additions & 16 deletions packages/tweakpane/src/main/ts/pane/pane.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
PluginPool,
TabBladePlugin,
TpError,
TpPlugin,
TpPluginBundle,
ValueMap,
ViewProps,
Expand Down Expand Up @@ -101,33 +100,26 @@ export class Pane extends RootApi {
}

public registerPlugin(bundle: TpPluginBundle): void {
if (bundle.css) {
embedStyle(this.document, `plugin-${bundle.id}`, bundle.css);
}

const plugins =
'plugin' in bundle
? [bundle.plugin]
: 'plugins' in bundle
? bundle.plugins
: [];
plugins.forEach((p) => {
this.pool_.register(p);
this.embedPluginStyle_(p);
this.pool_.register(bundle.id, p);
});
}

private embedPluginStyle_(plugin: TpPlugin): void {
if (plugin.css) {
embedStyle(this.document, `plugin-${plugin.id}`, plugin.css);
}
}

private setUpDefaultPlugins_() {
// NOTE: This string literal will be replaced with the default CSS by Rollup at the compilation time
embedStyle(this.document, 'default', '__css__');

this.pool_.getAll().forEach((plugin) => {
this.embedPluginStyle_(plugin);
});

this.registerPlugin({
id: 'default',
// NOTE: This string literal will be replaced with the default CSS by Rollup at the compilation time
css: '__css__',
plugins: [
ListBladePlugin,
SeparatorBladePlugin,
Expand Down

0 comments on commit 24f8990

Please sign in to comment.